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?

[ABC457] ABC 457(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

0
Posted at

[ABC457] ABC 457(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

A問題

  • 0-indexed に気をつけよう
A.py
"""
<方針>
- 0-indexed に気をつけよう
"""
# 入力
N = int(input())
A = list(map(int, input().split()))
X = int(input())

# 0-indexに気をつけて添字を指定
print(A[X-1])

B問題

  • 色々気をつけて添字を指定するだけ❤️
B.py
"""
<方針>
- 色々気をつけて添字を指定するだけ❤️
"""
N = int(input())
LA = [list(map(int, input().split())) for _ in range(N)]
X, Y = map(int, input().split())

print(LA[X-1][Y])

C問題

方針

  • 馬鹿正直に配列は展開できない.
  • だから,K番目だけを考えよう.

前提

  • C問題あたりで,TLEになる人は,制約条件を見る癖をつけよう.
  • AB問題では,基本的に制約条件を見ずにやっても解ける.
  • しかし,C問題以降では,制約条件を見ないと必ずTLEすると思っても良い.
  • 詳しい話は私の352回の記事C問題の解説に記したので,是非参照してほしい.
C.py
"""
<方針>
- 馬鹿正直に配列は展開できない.
- だから,K番目だけを考えよう.
"""
N, K = map(int, input().split())
LA = [list(map(int, input().split())) for _ in range(N)]
CC = list(map(int, input().split()))

for i in range(N):
  L, *A = LA[i]
  C = CC[i]
  
  # この配列の中にKがある  
  if(K <= L*C):
    print(A[(K-1)%L])
    exit()
  # まだまだ先
  else:
    K -= L*C

補足

関係するリンク(参考文献など)

筆者について

その他

  • 間違いを含んでいる可能性があります.
  • 方針と言いつつ,方針ではない感想などを書いている可能性があります.
  • A問題から解説がだんだん省略されます.
  • コードに書かれている解説の文言と,その上に書いてある解説の文言を変えている場合があります.

最後に一言

  • 明らか諸々のモチベが下がってる.
  • 宅建士と正直不動産だけ面白い.
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?