[codeforce][Python] #690 A. Favorite Sequence 좌우영역에서 검사하는 것으로 투포인터를 이용했습니다. import sys input = sys.stdin.readline for test in range(int(input())): n = int(input()) arr = list(map(int, input().split())) left, right = 0, n - 1 answer = [] while left practivceAlgorithm/codeforce 2021.12.07
[백준][Python] 1487 물건팔기 import sys input = sys.stdin.readline N = int(input()) costs = [list(map(int, input().split())) for _ in range(N)] costs.sort() dp = [0] * N max_profit = 0 answers = [] for i in range(N): for j in range(i, N): tmp = costs[i][0] - costs[j][1] if tmp > 0: dp[i] += tmp if max_profit practivceAlgorithm/백준 2021.12.03
[백준][Python] 2589 보물섬 기본적인 bfs문제입니다. import sys input = sys.stdin.readline from collections import deque def bfs(i, j): q = deque() q.append([i, j]) max_n = 0 while q: a, b = q.popleft() for k in range(4): x = a + dx[k] y = b + dy[k] if 0 practivceAlgorithm/백준 2021.11.15
[Programmers][Python][2021 카카오 인턴십] 표 편집 우선순위 큐 두개를 이용해 가운데값을 k로 운용했습니다. 마지막에 left를 right로 굳이 안옮겨도됐을텐데 조금 아쉽습니다. 또 set을 썼으면 좀 더 출력부분이 깔끔한 반복문으로 처리됐을 것 같습니다. 다른 분들은 연결리스트를 구현하신분들이 많았습니다. from heapq import heappop, heappush def solution(n, k, cmd): left, right, delete = [-i for i in range(k-1, -1, -1)], [i for i in range(k, n)], [] for command in cmd: c, *num = command.split() if c == 'U': cnt = int(num.pop()) for _ in range(cnt): heappu.. practivceAlgorithm/programmers 2021.11.14
[Programmers][Python][2021 카카오 인턴십] 거리두기 확인하기 각 지점에서 거리 2까지만 확인해주면 됩니다. 거리두기 안지켰으면 바로 return False 해줍니다. delta = ((0, 1), (1, 0), (0, -1), (-1, 0)) def is_check(place): q = [] for i in range(5): for j in range(5): if place[i][j] == 'P': q.append((i, j, 0, set())) while q: x, y, dist, visited = q.pop() visited.add((x, y)) for dx, dy in delta: nx, ny = x + dx, y + dy if 0 practivceAlgorithm/programmers 2021.11.14
[백준][Python] 17216 가장 큰 감소 부분 수열 결과를 누적시켜주며 끝까지 간다 import sys input = sys.stdin.readline N = int(input()) arr = list(map(int, input().split())) dp = arr[:] for i in range(N): for j in range(i): if arr[j] > arr[i]: dp[i] = max(dp[i], dp[j] + arr[i]) print(max(dp)) practivceAlgorithm/백준 2021.11.09
[Codeforce][Python] #702 G. Old Floppy Drive 이거 cycle을 산출하는 공식이 이해가 안됨. 이번주 내로 해결할 예정 import sys input = sys.stdin.readline from bisect import bisect_left # 풀이 참고했는데 for test in range(int(input())): n, m = map(int, input().split()) arr = list(map(int, input().split())) prefix_sum, idxes, idx, total = [], [], 0, 0 for num in arr: total += num if not prefix_sum or prefix_sum[-1] < total: prefix_sum.append(total) idxes.append(idx) idx += 1 x .. practivceAlgorithm/다시 봐야할 문제들 2021.11.09
[백준][Python] 16162 가희와 3단 고음 몇단 고음까지 올라가냐? 좀 문제가 직관성이 떨어지지만 그냥 target을 올려가면서 hit하면 올려주면 된다. n, a, d = map(int,input().split()) L = list(map(int,input().split())) check = 0 for pt in range(n): if L[pt] == a: check += 1 a += d print(check) practivceAlgorithm/백준 2021.11.09
[Codeforce][Python] #702 F. Equalize the Array Counter map을 만든 후 set에 조사할 count들을 모은 후 순회하며 그 cnt보다 크면 cnt에 맞춰주고 작으면 0에 맞춰주는 식으로 풀었습니다. import sys input = sys.stdin.readline from collections import defaultdict for test in range(int(input())): n = int(input()) arr = list(map(int, input().split())) counter = defaultdict(int) for num in arr: counter[num] += 1 candidate = set() for target in counter.values(): candidate.add(target) answer = float.. practivceAlgorithm/codeforce 2021.11.07
[Codeforce][Python] #702 D. Permutation Transformation 분할시키면서 실제 subtree도 분할시켰습니다. import sys input = sys.stdin.readline def make_tree(depth, a): if not a: return a max_num = 0 for idx, num in enumerate(a): if max_num < num: max_idx = idx max_num = num answer[dic[max_num]] = depth make_tree(depth+1, a[:max_idx]) make_tree(depth+1, a[max_idx+1:]) for test in range(int(input())): n = int(input()) arr = list(map(int, input().split())) dic = {num: idx f.. practivceAlgorithm/codeforce 2021.11.07