Skip to content

Commit 3148b1b

Browse files
committed
abc338
1 parent 8ce83b5 commit 3148b1b

File tree

8 files changed

+167
-1
lines changed

8 files changed

+167
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
s = list(input())
2+
3+
flag = True
4+
big_alphabet = set([chr(ord("A") + i) for i in range(26)])
5+
small_alphabet = set([chr(ord("a") + i) for i in range(26)])
6+
7+
if s[0] not in big_alphabet:
8+
flag = False
9+
10+
for i in range(1, len(s)):
11+
if s[i] not in small_alphabet:
12+
flag = False
13+
14+
if flag:
15+
print("Yes")
16+
else:
17+
print("No")

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from collections import defaultdict
2+
3+
counter = defaultdict(int)
4+
5+
s = list(input())
6+
7+
for si in s:
8+
counter[si] += 1
9+
10+
ans = [-1, ""]
11+
for i in range(26):
12+
si = chr(ord("a") + i)
13+
cnt = counter[si]
14+
if ans[0] < cnt:
15+
ans = [cnt, si]
16+
print(ans[1])

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
n = int(input())
2+
q = list(map(int, input().split()))
3+
a = list(map(int, input().split()))
4+
b = list(map(int, input().split()))
5+
6+
def solve(q, x):
7+
# 材料qでxを作れる最大数
8+
ans = []
9+
for qi, xi in zip(q, x):
10+
if xi == 0:
11+
continue
12+
ans.append(qi // xi)
13+
return min(ans)
14+
15+
# 全探索
16+
ans = 0
17+
max_a = solve(q, a)
18+
for i in range(0, max_a + 1):
19+
q_tmp = [qi - i * xi for qi, xi in zip(q, a)]
20+
max_b = solve(q_tmp, b)
21+
ans = max(ans, i + max_b)
22+
print(ans)
23+

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from collections import deque, Counter
2+
n, m = map(int, input().split())
3+
x = list(map(int, input().split()))
4+
5+
# xと(x+1)mod nを繋いでいるので経路は時計回りか反時計回り
6+
# 最初に適当に最短になるように移動させて、最も通行回数が少ない辺を削除する
7+
# 通行回数が少ない辺が複数ある場合は全部試す?(未証明だが一旦1箇所で試す)
8+
9+
# 累積和の差分を格納
10+
counter = [0] * (2 * (n + 1))
11+
q = deque(x)
12+
13+
current_num = q.popleft()
14+
cost = 0
15+
while q:
16+
next_num = q.popleft()
17+
max_num = max(current_num, next_num)
18+
min_num = min(current_num, next_num)
19+
# 時計回り
20+
diff1 = max_num - min_num
21+
# 反時計回り
22+
diff2 = (n + min_num) - max_num
23+
if diff1 < diff2:
24+
counter[min_num] += diff2 - diff1
25+
counter[max_num] -= diff2 - diff1
26+
elif diff1 > diff2:
27+
counter[max_num] += diff1 - diff2
28+
counter[min_num + n] -= diff1 - diff2
29+
30+
cost += min(diff1, diff2)
31+
# print(cost, current_num, next_num, diff1, diff2)
32+
current_num = next_num
33+
# print(counter)
34+
# 累積和
35+
losses = [0] * (2 * (n + 1))
36+
for i in range(1, 2 * (n + 1)):
37+
losses[i] += losses[i - 1] + counter[i]
38+
39+
for i in range(1, n + 1):
40+
losses[i] = losses[i] + losses[n + i]
41+
print(cost + min(losses[1:n + 1]))

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import deque
2+
n = int(input())
3+
ab = []
4+
stuck = deque()
5+
6+
for i in range(n):
7+
a, b = map(int, input().split())
8+
min_ab = min(a, b)
9+
max_ab = max(a, b)
10+
ab.append([min_ab, "a", i])
11+
ab.append([max_ab, "b", i])
12+
ab.sort()
13+
14+
ans = False
15+
for v, is_ab, i in ab:
16+
if is_ab == "a":
17+
stuck.append(i)
18+
else:
19+
if len(stuck) > 0 and stuck[-1] == i:
20+
stuck.pop()
21+
else:
22+
ans = True
23+
break
24+
25+
print("Yes" if ans else "No")

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
INF = float('inf')
2+
n, m = map(int, input().split())
3+
G = [[INF] * n for _ in range(n)]
4+
5+
for _ in range(m):
6+
u, v, w = map(int, input().split())
7+
G[u - 1][v - 1] = w
8+
9+
def warshall_floyd(n, d):
10+
# 空間計算量: O(n^2)
11+
# 時間計算量: O(n^3)
12+
# よって、n <= 10^2程度が限界
13+
for k in range(n):
14+
for i in range(n):
15+
for j in range(n):
16+
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
17+
return d
18+
19+
G = warshall_floyd(n, G)
20+
21+
def solve_tsp_dp(n, g):
22+
# n: 頂点数
23+
# m: 辺数
24+
# g: グラフ
25+
# https://qiita.com/Ll_e_ki/items/fa475f5bb224ada9be97
26+
dp = [[INF] * n for _ in range(2**n)]
27+
# どこスタートでも良い
28+
for i in range(n):
29+
dp[2**i][i] = 0
30+
for S in range(2**n):
31+
for v in range(n):
32+
for u in range(n):
33+
if not (S >> u) & 1 and S != 0: # ①
34+
continue
35+
if (S >> v) & 1 == 0:
36+
if dp[S][u] + g[u][v] < dp[S | (1 << v)][v]:
37+
dp[S | (1 << v)][v] = dp[S][u] + g[u][v]
38+
return min(dp[2**n - 1])
39+
40+
ans = solve_tsp_dp(n, G)
41+
if ans == INF:
42+
print("No")
43+
else:
44+
print(ans)

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

Whitespace-only changes.

dockerfiles/Dockerfile.new

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM --platform=linux/x86_64 ubuntu:22.04
55

66
# ユーザの追加
77
ARG UID
8-
ENV USER_NAME=atcoder_user
8+
ENV USER_NAME=player
99
RUN useradd $USER_NAME -u $UID -m
1010

1111
ARG DEBIAN_FRONTEND=noninteractive

0 commit comments

Comments
 (0)