This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from collections import deque | |
| sys.setrecursionlimit(10**9) | |
| def can_reach(v, current_visited): | |
| if v == Y: | |
| return True | |
| que = deque([v]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N = int(input()) | |
| a = list(map(int, input().split())) | |
| takahashi_best_score = -float("inf") | |
| for i in range(N): # 高橋君がiを選んだ | |
| aoki_score = -float("inf") | |
| aoki_j = None | |
| for j in range(N): # 青木君がjを選んだ | |
| if i == j: | |
| continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import heapq | |
| N = int(input()) | |
| slimes = {} | |
| que = [] | |
| for _ in range(N): | |
| s, c = map(int, input().split()) | |
| slimes[s] = c | |
| heapq.heappush(que, s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import deque, defaultdict | |
| H, W, N = map(int, input().split()) | |
| h2i = defaultdict(list) # 高さhのピースのインデックスを管理 | |
| w2i = defaultdict(list) # 幅wのピースのインデックスを管理 | |
| pieces = [] | |
| for i in range(N): | |
| h, w = map(int, input().split()) | |
| pieces.append((h, w)) | |
| h2i[h].append(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N, X, M = map(int, input().split()) | |
| arr = [] | |
| idx = [-1] * M | |
| curr = X | |
| while idx[curr] == -1: | |
| idx[curr] = len(arr) | |
| arr.append(curr) | |
| curr = (curr * curr) % M | |
| loop_start_idx = idx[curr] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import bisect | |
| def get_match_length(s, t): | |
| i = 0 | |
| for c in s: | |
| if i < len(t) and t[i] == c: | |
| i += 1 | |
| return i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def gen_array(arr): | |
| if len(arr) == N: | |
| return [arr] | |
| all_lst = [] | |
| for num in range(arr[-1], M + 1): | |
| all_lst.extend(gen_array(arr + [num])) | |
| return all_lst | |
| N, M, Q = map(int, input().split()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N, Q = map(int, input().split()) | |
| x = list(map(int, input().split())) | |
| # (1) 各クエリ終了時点の|S|の累積和を作成 | |
| s = set() | |
| s_size_acc = [0] | |
| for i in range(Q): | |
| curr_x = x[i] | |
| if curr_x in s: | |
| s.remove(curr_x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import deque | |
| def bfs(v): | |
| dist = [-1] * N | |
| dist[v] = 0 | |
| que = deque([v]) | |
| while que: | |
| v = que.popleft() | |
| for u in T[v]: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import deque | |
| def bfs(island_id, i, j): | |
| G[i][j] = island_id | |
| que = deque([(i, j)]) | |
| while que: | |
| i, j = que.popleft() | |
| for di, dj in dirs: | |
| ni, nj = i + di, j + dj |
NewerOlder