Skip to content

Commit e39c549

Browse files
committed
abc336
1 parent 29ae5fa commit e39c549

File tree

7 files changed

+144
-0
lines changed

7 files changed

+144
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n = int(input())
2+
ans = ["L"]
3+
for _ in range(n):
4+
ans.append("o")
5+
ans.append("n")
6+
ans.append("g")
7+
print("".join(ans))

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
n = int(input())
2+
3+
ans = 0
4+
while n > 0:
5+
if n & 1 == 0:
6+
ans += 1
7+
else:
8+
break
9+
n >>= 1
10+
print(ans)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
n = int(input())
2+
3+
# nの5進数を考える
4+
def base_5(n):
5+
ans = []
6+
if n == 0:
7+
return [0]
8+
while n > 0:
9+
ans.append(n % 5)
10+
n //= 5
11+
return ans[::-1]
12+
13+
mapping = [0, 2, 4, 6, 8]
14+
ans = int("".join(map(str, [mapping[x] for x in base_5(n - 1)])))
15+
print(ans)
16+

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
n = int(input())
2+
a = list(map(int, input().split()))
3+
a = [0] + a + [0]
4+
5+
# 左右から挟む
6+
# 左から
7+
possible = [0 for _ in range(len(a))]
8+
for i in range(1, len(a)):
9+
possible[i] = min(a[i], possible[i - 1] + 1)
10+
11+
# 右から
12+
for i in range(len(a) - 2, 0, -1):
13+
possible[i] = min(possible[i], possible[i + 1] + 1)
14+
print(max(possible))

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
n = int(input())
2+
3+
# その桁をxにしたときのmod pを前計算して後でmod pがゼロになるものを数える
4+
# 下の桁からその桁以下を任意の数にしてmod pになるものの数を下から数える
5+
# 9999...が桁和最大で、9 * 15 = 135
6+
7+
counts = [[0 for _ in range(135)] for _ in range(15)]
8+
9+
# 1桁目
10+
for i in range(1, 135):
11+
for j in range(1, 10):
12+
counts[0][i] =
13+
14+
for i in range(1, 15):
15+
for j in range(135):
16+
counts[i][j] = counts[i - 1][j]
17+
counts[i][j] += counts[i - 1][(j - i * (10 ** (i - 1))) % 135]
18+
counts[i][i * (10 ** (i - 1)) % 135] += 1
19+

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import sys
2+
import pypyjit
3+
from collections import defaultdict
4+
pypyjit.set_param('max_unroll_recursion=-1')
5+
input = lambda: sys.stdin.readline().rstrip()
6+
sys.setrecursionlimit(20000000)
7+
INF = float('inf')
8+
9+
h, w = map(int, input().split())
10+
s = [list(map(int, input().split())) for _ in range(h)]
11+
12+
# 連続して同じところを操作すると元に戻るので、最初だけ4つの選択肢、そのあとは3つの選択肢
13+
# 左上、右上、左下、右下
14+
15+
def is_state_correct(X):
16+
for i in range(h):
17+
for j in range(w):
18+
if X[i][j] != i * w + j + 1:
19+
return False
20+
return True
21+
22+
def spin(pattern_num, X):
23+
# 左上、右上、左下、右下
24+
tmp_X = [[0 for _ in range(w)] for _ in range(h)]
25+
dxy = [[0, 0], [0, 1], [1, 0], [1, 1]]
26+
x = dxy[pattern_num][0]
27+
y = dxy[pattern_num][1]
28+
for i in range(h - 1):
29+
for j in range(w - 1):
30+
tmp_X[i + x][j + y] = X[h - 2 - i + x][w - 2 - j + y]
31+
if y == 0:
32+
for i in range(h):
33+
tmp_X[i][w - 1] = X[i][w - 1]
34+
else:
35+
for i in range(h):
36+
tmp_X[i][0] = X[i][0]
37+
if x == 0:
38+
for j in range(w):
39+
tmp_X[h - 1][j] = X[h - 1][j]
40+
else:
41+
for j in range(w):
42+
tmp_X[0][j] = X[0][j]
43+
return tmp_X
44+
45+
def state_str(X):
46+
return '_'.join(['_'.join(map(str, x)) for x in X])
47+
48+
def display(X):
49+
return '\n'.join([' '.join(map(str, x)) for x in X])
50+
51+
visited = defaultdict(lambda: INF)
52+
visited[state_str(s)] = 0
53+
54+
ans = INF
55+
def dfs(X, pre_pattern_num = -1, depth = 1):
56+
for i in range(4):
57+
if i == pre_pattern_num:
58+
continue
59+
tmp_X = spin(i, X)
60+
state = state_str(tmp_X)
61+
if visited[state] < depth:
62+
continue
63+
visited[state] = depth
64+
if depth + 1 >= 21:
65+
continue
66+
dfs(tmp_X, i, depth + 1)
67+
68+
if is_state_correct(s):
69+
print(0)
70+
exit()
71+
72+
dfs(s)
73+
state = "_".join([str(x + 1) for x in range(h * w)])
74+
ans = visited[state]
75+
if ans == INF:
76+
print(-1)
77+
else:
78+
print(ans)

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

Whitespace-only changes.

0 commit comments

Comments
 (0)