0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC426をPythonで

Posted at

AtCoder Beginner Contest 426の解答等の速報的まとめ

A問題

サーバー名から順番を返す辞書を作成して比較

A
server =  {"Ocelot":0, "Serval":1, "Lynx":2}
x, y = input().split()
print("Yes" if server[x] >= server[y] else "No")

B問題

個数をカウントして1個のものを出力

B
from collections import defaultdict

d = defaultdict(int)

s = input()
for s_i in s:
    d[s_i] += 1

for key, val in d.items():
    if val == 1:
        exit(print(key))

C問題

あるクエリ以降バージョン$x$以前はそれ以降参照することがないので、参照しうるバージョンをメモして足していけばいい

C
n, q = map(int, input().split())

count = [1] * n
last_version = 0
for _ in range(q):
    x, y = map(lambda x:int(x) - 1, input().split())
    version_up = 0
    if last_version <= x:
        version_up = sum(count[last_version:x + 1])
        last_version = x + 1
        count[y] += version_up
    print(version_up)

D問題

処理を単純化すると

  1. 両端から探索して、探索終了する場所を決める
  2. 揃える数字を決める
  3. 数字が違う場合は探索終了地点に挿入
  4. 一緒の場合、違う数字にするため端へ挿入してから3の処理を行う

上の方針だと両端から計算できるので
座標圧縮した後尺取りの要領で計算したが1WA

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?