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?

[ABC463] ABC 463のA~C問題をPythonで解説

0
Posted at

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

A問題

  • 小学三年生でやった比率の計算やね。
A.py
"""
<方針>
- 小学三年生でやった比率の計算やね。
"""
# 入力
X, Y = map(int, input().split())

# 比率の条件
if(X*9 == Y*16):
  print("Yes")
else:
  print("No")

B問題

  • ord で座先をindexにするか。
  • for 文で愚直にやりますか。
B.py
"""
<方針>
- `ord` で座先をindexにするか。
- `for` 文で愚直にやりますか。
"""
N, X = input().split()
N = int(N)
X = ord(X) - ord("A")
SS = [input() for _ in range(N)]

for S in SS:
  if(S[X] == "o"):
    print("Yes")
    exit()

print("No")

C問題

方針

  • 時間を逆再生して、最大値を記録しよう。
  • pythonの仕様にも依存した、クソコードを書きます。

前提

  • C問題あたりで,TLEになる人は,制約条件を見る癖をつけよう.
  • AB問題では,基本的に制約条件を見ずにやっても解ける.
  • しかし,C問題以降では,制約条件を見ないと必ずTLEすると思っても良い.
  • 詳しい話は私の352回の記事C問題の解説に記したので,是非参照してほしい.
C.py
"""
<方針>
- 時間を逆再生して、最大値を記録しよう。
- pythonの仕様にも依存した、クソコードを書きます。
"""
N = int(input())
HL = [list(map(int, input().split())) for _ in range(N)]

Q = int(input())
T = list(map(int, input().split()))

HL.sort(key=lambda x: (-x[1], x[0]))
ma = -1
LH = {}
for h, l in HL:
  ma = max(ma, h)
  LH[l] = ma

TH = []
for l, h in reversed(LH.items()):
  TH.append([l, h])

for t in T:
  le = -1
  ri = len(TH)
  while abs(le-ri) > 1:
    mi = (le+ri)//2
    if(TH[mi][0] <= t):
      le = mi
    else:
      ri = mi
  
  print(TH[ri][1])

補足

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

筆者について

その他

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

最後に一言

  • (簿記2級受かりました!)
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?