Skip to content

Commit 14e261a

Browse files
committed
arc172
1 parent ba98609 commit 14e261a

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

atcoder/ARC/arc172/a.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import sys
2+
import pypyjit
3+
pypyjit.set_param('max_unroll_recursion=-1')
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sys.setrecursionlimit(20000000)
6+
from collections import defaultdict
7+
from bisect import bisect_left
8+
9+
h, w, n = map(int, input().split())
10+
a = list(map(int, input().split()))
11+
a.sort(reverse=True)
12+
13+
counter = defaultdict(lambda: 0)
14+
candidates = [0]
15+
for i in range(26):
16+
candidates.append(2**i)
17+
candidates.sort()
18+
19+
20+
def dfs(h, w):
21+
# h, wの大きさの正方形から作成可能なできるだけ大きい正方形の数
22+
if h == 1 or w == 1:
23+
counter[1] += h * w
24+
return
25+
min_hw = min(h, w)
26+
idx = bisect_left(candidates, min_hw)
27+
size = candidates[idx - 1]
28+
29+
if size == 0:
30+
return
31+
32+
h_cnt = h // size
33+
w_cnt = w // size
34+
counter[size] += h_cnt * w_cnt
35+
# あまり
36+
mod_h = h % size
37+
mod_w = w % size
38+
if mod_h == 0 and mod_w == 0:
39+
return
40+
elif mod_h == 0:
41+
dfs(mod_w, h)
42+
elif mod_w == 0:
43+
dfs(mod_h, w)
44+
else:
45+
if mod_h < mod_w:
46+
# あまりが大きい方を大きくする
47+
dfs(mod_w, h)
48+
dfs(mod_h, w_cnt * size)
49+
else:
50+
dfs(mod_h, w)
51+
dfs(mod_w, h_cnt * size)
52+
53+
dfs(h, w)
54+
a_count = defaultdict(lambda: 0)
55+
for ai in a:
56+
a_count[2**ai] += 1
57+
58+
# print(counter)
59+
# print(a_count)
60+
61+
flag = True
62+
for k in reversed(candidates[1:]):
63+
if counter[k] >= a_count[k]:
64+
counter[k] -= a_count[k]
65+
counter[k // 2] += 4 * counter[k]
66+
else:
67+
flag = False
68+
break
69+
70+
if flag:
71+
print("Yes")
72+
else:
73+
print("No")
74+

atcoder/ARC/arc172/b.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
n, k, l = map(int, input().split())
2+

atcoder/ARC/arc172/c.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from collections import defaultdict
2+
n = int(input())
3+
c = list(input())
4+
5+
# 遷移させるだけ
6+
# 遷移元と遷移先の状態によって中間状態を定める
7+
# 状態数はそんなに多くない(多分)のでsetで適当に扱う?
8+
9+
votes = [[0 for _ in range(4)] for _ in range(n + 1)]
10+
c1 = c[0]
11+
c = c[1:]
12+
if c1 == "A":
13+
votes[0][2] = 1
14+
else:
15+
votes[0][3] = 1
16+
17+
for i, ci in enumerate(c, start=1):
18+
if ci == "A":
19+
votes[i][0] = votes[i - 1][0] + 1
20+
votes[i][1] = votes[i - 1][1]
21+
votes[i][2] = votes[i - 1][2] + 1
22+
votes[i][3] = votes[i - 1][3]
23+
else:
24+
votes[i][0] = votes[i - 1][0]
25+
votes[i][1] = votes[i - 1][1] + 1
26+
votes[i][2] = votes[i - 1][2]
27+
votes[i][3] = votes[i - 1][3] + 1
28+
29+
# 最後
30+
if c1 == "A":
31+
votes[-1][0] = votes[-2][0] + 1
32+
votes[-1][1] = votes[-2][1]
33+
else:
34+
votes[-1][0] = votes[-2][0]
35+
votes[-1][1] = votes[-2][1] + 1
36+
37+
def stats(x, y):
38+
if x > y:
39+
return "A"
40+
elif x < y:
41+
return "B"
42+
else:
43+
return "C"
44+
45+
counter = defaultdict(lambda: defaultdict(lambda: 0))
46+
paths = [set() for _ in range(n - 1)]
47+
for i in range(1, n):
48+
start1 = stats(votes[i][0], votes[i][1])
49+
end1 = stats(votes[i][2], votes[i][3])
50+
end2 = stats(votes[i + 1][0], votes[i + 1][1])
51+
paths[i - 1].add(f"{start1} {end1} 1")
52+
paths[i - 1].add(f"{start1} {end2} 2")
53+
54+
start2 = stats(votes[i - 1][2], votes[i - 1][3])
55+
paths[i - 1].add(f"{start2} {end1} 3")
56+
57+
start_status1 = stats(votes[1][0], votes[1][1])
58+
start_status2 = stats(votes[0][2], votes[0][3])
59+
60+
for status in list(set([start_status1, start_status2])):
61+
counter[0][f"{status}_0"] = 1
62+
63+
for i in range(1, len(paths) + 1):
64+
for path in paths[i - 1]:
65+
start, end, path_type = path.split()
66+
counter[i][end] += counter[i - 1][start]
67+
68+
print(paths)
69+
print(counter)
70+
print(sum(counter[n - 1].values()))

atcoder/ARC/arc172/d.py

Whitespace-only changes.

0 commit comments

Comments
 (0)