본문 바로가기

반응형
SMALL

전체 글

21. Merge Two Sorted Lists https://leetcode.com/problems/merge-two-sorted-lists/description/ 이 문제는 풀긴 풀었다 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: ans = ListNode(0) tmp = ans while list1 != None and list2 != None: if (.. 더보기
9375 - 패션왕 신해빈 9375번: 패션왕 신해빈 첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로 (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다. www.acmicpc.net import sys input = sys.stdin.readline T = int(input()) dic = {} arr = [] R = 1 for _ in range(T): R = 1 arr = [] dic = {} N = int(input()) for __ in range(N): W, P = input().split() if dic.get(P) != None: arr.. 더보기
1389 - 케빈 베이컨의 6단계 법칙 1389번: 케빈 베이컨의 6단계 법칙 첫째 줄에 유저의 수 N (2 ≤ N ≤ 100)과 친구 관계의 수 M (1 ≤ M ≤ 5,000)이 주어진다. 둘째 줄부터 M개의 줄에는 친구 관계가 주어진다. 친구 관계는 A와 B로 이루어져 있으며, A와 B가 친구라는 뜻 www.acmicpc.net #include const int MAX_F = 100; int N, M; int map[MAX_F + 10][MAX_F + 10]; int result[MAX_F + 10][MAX_F + 10]; int queue[MAX_F + 10][2]; int s, e; void init() { scanf("%d %d", &N, &M); int s, e; for (int m = 0; m < M; ++m) { scanf("%.. 더보기
2014 - 소수의 곱 2014번: 소수의 곱 첫째 줄에 K(1 ≤ K ≤ 100), N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 K개의 소수가 오름차순으로 주어진다. 같은 소수가 여러 번 주어지는 경우는 없으며, 주어지는 소수는 모두 541보다 작거나 www.acmicpc.net #include typedef long long ll; const ll LK = 1e2; const ll LN = 1e5; ll K, N, R; ll arr[LK + 10]; void swap(ll& x, ll& y) {ll z = x; x = y; y = z;} int minComp(ll x, ll y) {return x < y;} struct PQ { ll hn; ll heap[LN * 10 + 10]; int (*comp)(ll,.. 더보기
3006 - 터보소트 3006번: 터보소트 첫째 줄에 N이 주어진다. N은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수이며, 배열의 크기이다. 둘째 줄부터 N개의 줄에는 1보다 크거나 같고, N보다 작거나 같은 수가 중복 없이 주어진다 www.acmicpc.net #include const int LN = 1e5; int N; int idxs[LN + 10]; int tree[LN * 3 + 10]; int seg_init(int n, int s, int e) { if (s == e) { return tree[n] = 1; } int m = (s + e) / 2; return tree[n] = seg_init(n * 2, s, m) + seg_init(n * 2 + 1, m + 1, e); } void upda.. 더보기
1395 - 스위치 1395번: 스위치 첫 줄에는 스위치의 개수 N(2 ≤ N ≤ 100,000)과 처리할 일의 개수 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 M개의 줄에 대해 각 줄에 처리할 일에 대한 정보가 담겨진 세 개의 정수 O, Si, Ti가 입력된다. O www.acmicpc.net #include typedef long long ll; const ll LN = 1e5; ll tree[LN * 3 + 10]; ll lazy[LN * 3 + 10]; ll N, M; void propagate(ll n, ll s, ll e) { if (lazy[n] % 2) { tree[n] = (e - s + 1) - tree[n]; if (s != e) { ++lazy[n * 2]; ++lazy[n * 2 + 1]; .. 더보기
1074 - Z 1074번: Z 한수는 크기가 2N × 2N인 2차원 배열을 Z모양으로 탐색하려고 한다. 예를 들어, 2×2배열을 왼쪽 위칸, 오른쪽 위칸, 왼쪽 아래칸, 오른쪽 아래칸 순서대로 방문하면 Z모양이다. N > 1인 경우, 배열을 www.acmicpc.net #include int N, r, c; int res; int sqrt(int num, int N) { int n = 0; int res = 1; for (int n = 0; n < N; ++n) { res *= num; } return res; } void init() { scanf("%d %d %d", &N, &r, &c); } void cal(int cs, int rs, int ce, int re) { int cm = (cs + ce) / 2; i.. 더보기
19646 - Random Generator 19646번: Random Generator 국렬이는 1부터 N까지의 양의 정수로 이루어진 순열을 주어진 양의 정수 w1 ... , wN를 이용해서 무작위로 만들 것이다. 다음은 무작위로 순열을 만드는 방법이다. 1부터 N까지의 양의 정수 i (1 ≤ www.acmicpc.net #include const int LN = 2e5; int R; int R_ARR[LN]; int tree[LN * 3 + 10]; int N; int push(int n, int s, int e, int t, int v) { if (s == e && s == t) { tree[n] = v; return tree[n]; } if (t < s || e < t) { return tree[n]; } int m = (s + e) / 2.. 더보기

반응형
LIST