ユニークビジョンプログラミングコンテスト2025 春(AtCoder Beginner Contest 398)の解答等の速報的まとめ
A問題
-を半分くらい埋めて=をいい感じにする
A
n = int(input())
s = (n - 1) // 2
print("-" * s + "=" * (1 if n % 2 else 2) + "-" * s)
B問題
3枚以上ある数の存在とペアをつくれる数が(3枚以上あるものも含め)2種類以上あるか調べる
B
A = list(map(int, input().split()))
d = dict()
for a_i in A:
if a_i not in d:
d[a_i] = 0
d[a_i] += 1
three_flag = False
two_count = 0
for val in d.values():
if val >= 2:
two_count += 1
if val >= 3:
three_flag = True
print("Yes" if three_flag and two_count >= 2 else "No")
C問題
1つしかない数の中で最大のものを求め、その場所を出力する
C
n = int(input())
a = list(map(int, input().split()))
d = dict()
for a_i in a:
if a_i not in d:
d[a_i] = 0
d[a_i] += 1
ans = -1
for key, val in d.items():
if val == 1:
ans = max(ans, key)
print(ans if ans < 0 else a.index(ans) + 1)
D問題
煙でなく焚き火と高橋君を動かして調べる
D
n, r, c = map(int, input().split())
s = input()
smoke = {(0, 0)}
x, y = 0, 0
arr = {"N":(1, 0), "S":(-1, 0), "W":(0, 1), "E":(0, -1)}
ans = list()
for s_i in s:
x += arr[s_i][0]
y += arr[s_i][1]
smoke.add((x, y))
ans.append("1" if (r + x, y + c) in smoke else "0")
print(*ans, sep="")
F問題
後ろから切り取って最長になる回文を求め、そうでない場所を後ろに反転させて繋げたものが答え
回文判定はdequeで行う
F
from collections import deque
def answer(s):
print(*s, sep="")
s = list(input())
n = len(s)
ans = n - 1
s_ = s.copy()
t_right = deque()
t_left = deque()
while s_:
s_i = s_.pop()
t_right.append(s_i)
t_left.appendleft(s_i)
if t_right == t_left:
ans = len(s_)
answer(s + s[:ans][::-1])