Skip to content

Commit 29ae5fa

Browse files
committed
abc335
1 parent f827e89 commit 29ae5fa

7 files changed

Lines changed: 129 additions & 0 deletions

File tree

atcoder/abc/abc301-400/abc335/a.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
s = list(input())
2+
s[-1] = "4"
3+
print(*s, sep="")

atcoder/abc/abc301-400/abc335/b.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
l = set()
2+
n = int(input())
3+
4+
for x in range(n + 1):
5+
for y in range(n + 1):
6+
for z in range(n + 1):
7+
if x + y + z <= n:
8+
l.add((x, y, z))
9+
l = list(l)
10+
l.sort()
11+
l = [" ".join(map(str, x)) for x in l]
12+
13+
print(*l, sep="\n")

atcoder/abc/abc301-400/abc335/c.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
import pypyjit
3+
4+
pypyjit.set_param('max_unroll_recursion=-1')
5+
input = lambda: sys.stdin.readline().rstrip()
6+
7+
directions = {
8+
"L": [-1, 0],
9+
"R": [1, 0],
10+
"U": [0, 1],
11+
"D": [0, -1]
12+
}
13+
14+
n, q = map(int, input().split())
15+
queries = []
16+
for _ in range(q):
17+
query_type, x = input().split()
18+
queries.append((query_type, x))
19+
20+
ans = []
21+
dragon = []
22+
for i in reversed(range(1, n + 1)):
23+
dragon.append([i, 0])
24+
25+
for query_type, x in queries:
26+
if query_type == "1":
27+
next_head_x = dragon[-1][0] + directions[x][0]
28+
next_head_y = dragon[-1][1] + directions[x][1]
29+
dragon.append([next_head_x, next_head_y])
30+
else:
31+
x = int(x)
32+
current_x = dragon[-x]
33+
ans.append(f"{current_x[0]} {current_x[1]}")
34+
print(*ans, sep="\n")

atcoder/abc/abc301-400/abc335/d.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
n = int(input())
2+
3+
# 外側から埋めるうずまき
4+
# 中央はT
5+
ans = [[0 for _ in range(n)] for _ in range(n)]
6+
ans[0][0] = 1
7+
ans[n // 2][n // 2] = "T"
8+
current_pos = [1, 0]
9+
current_num = 2
10+
status = 0
11+
dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
12+
while True:
13+
ans[current_pos[0]][current_pos[1]] = current_num
14+
dx, dy = dxy[status % 4]
15+
next_pos = [current_pos[0] + dx, current_pos[1] + dy]
16+
if 0 <= next_pos[0] < n and 0 <= next_pos[1] < n:
17+
if ans[next_pos[0]][next_pos[1]] == "T":
18+
break
19+
elif ans[next_pos[0]][next_pos[1]] == 0:
20+
ans[next_pos[0]][next_pos[1]] = current_num
21+
current_pos = next_pos
22+
current_num += 1
23+
else:
24+
status += 1
25+
else:
26+
status += 1
27+
out = []
28+
for ansi in ans:
29+
out.append(" ".join(map(str, ansi)))
30+
print(*out, sep="\n")

atcoder/abc/abc301-400/abc335/e.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import sys
2+
from collections import defaultdict, deque
3+
input = lambda: sys.stdin.readline().rstrip()
4+
sys.setrecursionlimit(20000000)
5+
INF = float("inf")
6+
7+
n, m = map(int, input().split())
8+
a = list(map(int, input().split()))
9+
uv = []
10+
paths = defaultdict(lambda: [])
11+
for _ in range(m):
12+
u, v = map(int, input().split())
13+
if a[u - 1] <= a[v - 1]:
14+
paths[u].append(v)
15+
if a[v - 1] <= a[u - 1]:
16+
paths[v].append(u)
17+
18+
# 各頂点にそこにいくまでの最高得点を記録していく
19+
scores = defaultdict(lambda: -INF)
20+
q = [(1, 1, 0)]
21+
visited_path = set()
22+
path = []
23+
24+
while q:
25+
current_node_num, current_score, depth = q.pop()
26+
while len(path) > depth:
27+
visited_path.discard(path.pop())
28+
if scores[current_node_num] > current_score:
29+
# もっと良い手順がある
30+
continue
31+
if current_node_num == n:
32+
continue
33+
value = a[current_node_num - 1]
34+
for next_node_num in paths[current_node_num]:
35+
if next_node_num in visited_path:
36+
continue
37+
next_score = current_score
38+
if value != a[next_node_num - 1]:
39+
next_score += 1
40+
if scores[next_node_num] >= next_score:
41+
continue
42+
43+
q.append((next_node_num, next_score, depth + 1))
44+
scores[next_node_num] = max(scores[next_node_num], next_score)
45+
46+
if scores[n] == -INF:
47+
print(0)
48+
else:
49+
print(scores[n])

atcoder/abc/abc301-400/abc335/f.py

Whitespace-only changes.

atcoder/abc/abc301-400/abc335/g.py

Whitespace-only changes.

0 commit comments

Comments
 (0)