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?

ABC417の記録

Posted at

はじめに

なかなか成長を感じられない日々。

成績:ABC3完(600)

A

スライスで区間を指定してprintする。

A
n,a,b = map(int,input().split())
s = input()
print(s[a:n-b])

B

言われたとおりにやる。

B
n,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for b in B:
    if b in A:
        A.remove(b)
print(*A)

いろいろ条件が付いているが制約が小さいので無視。条件に惑わされて時間を喰ってしまった。

C

どうやっても$O(n^2)$かかるのでは?と思っていたが、$A_i+i = j-A_j$ ($i<j$のとき)となることに気づく。
そこで、$A$の各要素に対してそのインデックスを$i$とした時に$i+A_i$と$i-A_i$をそれぞれ別の辞書に記録しておき、2つの辞書で被っている者同士の数をかけてその合計が答えになる。

C
n = int(input())
A = list(map(int,input().split()))
lsi = {}
lsj = {}
ans = 0
for i in range(n):
    if (A[i] + i + 1) in lsi:
        lsi[A[i] + i + 1] += 1
    else:
        lsi[A[i] + i + 1] = 1
    
    if (i + 1 - A[i]) in lsj:
        lsj[i + 1 - A[i]] += 1
    else:
        lsj[i + 1 - A[i]] = 1
for i in lsi:
    if i in lsj:
        ans += lsj[i] * lsi[i]
print(ans)

正直これで過不足なく数えられている理屈はよく分からないのだが……

D

解説を見る限りかなり難しそうではある。後日挑戦。

D

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?