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 get_lcp(str1, str2): | |
| ret = 0 | |
| for s1, s2 in zip(str1, str2): | |
| if s1 != s2: | |
| break | |
| ret += 1 | |
| return ret | |
| N = int(input()) |
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, D, K = map(int, input().split()) | |
| LR = [list(map(int, input().split())) for _ in range(D)] | |
| ST = [list(map(int, input().split())) for _ in range(K)] | |
| ans = [-1] * K | |
| for i in range(D): # i日目 | |
| l, r = LR[i] | |
| for j in range(K): # j番目の民族の移動 | |
| if ans[j] != -1: | |
| 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 | |
| from collections import deque | |
| queA = deque() # まだソートされてない配列Aを表現 | |
| heapA = [] # ソート済みの配列Aを表現 | |
| Q = int(input()) | |
| for _ in range(Q): | |
| query = list(map(int, input().split())) | |
| if query[0] == 1: | |
| x = query[1] |
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 | |
| def dijkstra(start_node, G): # ダイクストラ法 | |
| dist = [float("inf")] * N | |
| dist[start_node] = 0 | |
| que = [(0, start_node)] | |
| while que: | |
| d, pos = heapq.heappop(que) | |
| if d > dist[pos]: # ここで速度改善! |
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
| H, W = map(int, input().split()) | |
| S = [list(input()) for _ in range(H)] | |
| ans = 0 | |
| for i in range(H - 1): | |
| for j in range(W - 1): | |
| cnt = 0 | |
| for di, dj in ((0, 0), (0, 1), (1, 0), (1, 1)): | |
| if S[i + di][j + dj] == "#": | |
| cnt += 1 | |
| if cnt == 1 or cnt == 3: |
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 get_mex(a, b, c): | |
| mex = [False] * 4 | |
| mex[a] = mex[b] = mex[c] = True | |
| for i in range(4): | |
| if mex[i]: | |
| continue | |
| return i | |
| N = int(input()) |
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, L, R = map(int, input().split()) | |
| A = list(map(int, input().split())) | |
| revA = A[::-1] # 逆順にしておく | |
| # dpl[i]: 左からi番目まで見たときの最小値 | |
| # dpr[i]: 右からi番目まで見たときの最小値 | |
| dpl = [0] * (N + 1) | |
| dpr = [0] * (N + 1) | |
| for i in range(N): |
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 atcoder.dsu import DSU | |
| N, M = map(int, input().split()) | |
| G = [[] * N for _ in range(N)] | |
| for _ in range(M): | |
| a, b = map(lambda x: int(x) - 1, input().split()) | |
| G[a].append(b) | |
| dsu = DSU(N) | |
| curr = 0 |
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()) | |
| T = input() | |
| # dp[r][0] : 0が偶数個(結果が1になる) | |
| # dp[r][1] : 0が奇数個(結果が0になる) | |
| dp = [[0] * 2 for _ in range(N + 1)] | |
| for r in range(1, N + 1): | |
| if T[r - 1] == "0": | |
| dp[r][0] = dp[r - 1][1] |
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()) | |
| D = [[0] * N for _ in range(N)] | |
| for i in range(N - 1): | |
| d = list(map(int, input().split())) | |
| for j in range(len(d)): | |
| D[i][i + j + 1] = d[j] | |
| D[i + j + 1][i] = d[j] | |
| dp = [0] * (1 << N) | |
| for bit in range(1 << N): |
NewerOlder