1
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?

ABC417をPythonで(A~C)

Posted at

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

A問題

問題文通り、先頭から$a$文字、後ろから$b$文字取る

A
n, a, b = map(int, input().split())
s = list(input())

for _ in range(a):
    s = s[1:]
for _ in range(b):
    s.pop()

print("".join(s))    

B問題

$a$の数字と個数で辞書に入れて、$b$の数列から順番に減らしている
あとから数列変形・ソートする

B
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = 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

for b_i in b:
    if b_i in d:
        d[b_i] -= 1

ans = list()
for key, val in d.items():
    if val > 0:
        ans += [key] * val

print(*sorted(ans))

C問題

問題文の条件から $i + a_i = j - a_j$ となる組み合わせを見つける
後ろから順番に見ていく

C
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
ans = 0
for i in range(n -1, -1, -1):
    ans += d[i + a[i]]
    d[i - a[i]] += 1

print(ans)

D問題

$x <= 500$ ならできるがそれ以上へのパラメータの計算方法がわからなかった

E問題

頂点の探索順を番号が小さい順になるようにDFSをしたがTLE

1
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
1
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?