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 solv(): | |
| stack = [] | |
| c_set = set() | |
| for c in S: | |
| if c == "(": | |
| stack.append(c) | |
| elif c == ")": | |
| while stack and stack[-1] != "(": | |
| ch = stack.pop() | |
| c_set.remove(ch) |
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()) | |
| P = list(map(int, input().split())) | |
| # (1) 末尾の昇順区間を探す | |
| i = N - 1 | |
| while i > 0 and P[i - 1] < P[i]: | |
| i -= 1 | |
| # (2) jは、昇順の始まりのひとつ左(交換対象) | |
| j = i - 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 sys | |
| sys.setrecursionlimit(10**7) | |
| def solv(): | |
| if N - 1 != M: | |
| return False | |
| for i in range(N): | |
| if len(G[i]) > 2: |
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()) | |
| Q = int(input()) | |
| boxes = [[] for _ in range(N + 1)] | |
| cards = {} | |
| for _ in range(Q): | |
| t, *q = map(int, input().split()) | |
| if t == 1: | |
| i, j = q | |
| boxes[j].append(i) | |
| if i not in cards: |
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_prime_list(n): | |
| prime_list = [True for _ in range(n + 1)] | |
| prime_list[0] = prime_list[1] = False | |
| for p in range(2, int(n**0.5) + 1): | |
| if prime_list[p]: | |
| i = p * p | |
| while i <= n: | |
| prime_list[i] = False | |
| i += p | |
| return [i for i, v in enumerate(prime_list) if 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
| import sys | |
| sys.setrecursionlimit(10**7) | |
| def f(k, memo): | |
| if k in memo: | |
| return memo[k] | |
| else: | |
| memo[k] = f(k // 2, memo) + f(k // 3, memo) |
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 | |
| sys.setrecursionlimit(10**9) | |
| def dfs(v, visited, ans): | |
| visited[v] = True | |
| ans.append(v + 1) | |
| for u in G[v]: | |
| if visited[u]: |
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()) | |
| A = [list(map(int, input().split())) for _ in range(H)] | |
| P = list(map(int, input().split())) | |
| dp = [[float("inf")] * W for _ in range(H)] | |
| dp[H - 1][W - 1] = 0 | |
| for i in range(H - 1, -1, -1): | |
| for j in range(W - 1, -1, -1): | |
| if i + 1 < H: | |
| dp[i][j] = min(dp[i][j], dp[i + 1][j]) | |
| if j + 1 < W: |
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, M = map(int, input().split()) | |
| imos = [0] * (N + 2) | |
| for _ in range(M): | |
| l, r = map(int, input().split()) | |
| imos[l] += 1 | |
| imos[r + 1] -= 1 | |
| for i in range(1, len(imos)): | |
| imos[i] += imos[i - 1] | |
| print(min(imos[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, M, Q = map(int, input().split()) | |
| contests = [set() for _ in range(N)] | |
| all_ok = [False] * N | |
| for _ in range(Q): | |
| t, *query = map(int, input().split()) | |
| if t == 1: | |
| x, y = query[0] - 1, query[1] - 1 | |
| contests[x].add(y) | |
| elif t == 2: | |
| x = query[0] - 1 |
NewerOlder