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?

More than 3 years have passed since last update.

Atcoder ABC164 A-CをPythonで

Posted at

D問題を完全に理解してから書こうと思ってましたが、時間かかりそうなのでわかり次第追記します。

#A. Sheep and Wolves
2つの値を比べる。

ABC164a.py
s,w=map(int,input().split())
 
if w>=s:
    print("unsafe")
else:
    print("safe")

#B. Battle
Modとか取るのかなとも思いましたが、先攻後攻等を考えるのが手間なので素直に実装

ABC164b.py
a,b,c,d=map(int,input().split())

while True:
    c-=b
    if c<=0:
        print("Yes")
        exit()
    a-=d
    if a<=0:
        print("No")
        exit()

#C. Gacha
配列中のユニークな個数を数えるだけ。

ABC164c.py
n=int(input())
s=[input() for _ in range(n)]

print(len(set(s)))

と、ここまで10分で終えて今回いけるかなーと思いましたがD問題で悩んだ挙句3完止まりでした。

D. Multiple of 2019
愚直に実装すると$O(N^2)$なので確実にTLEです。ぐぬぬ

ABC164d_TLE.py
s=input()

ans=0

for l in range(len(s)-3):
    for r in range(l+4,len(s)+1):
        a=s[l:r]
        if int(a)%2019==0:
            ans+=1
            
print(ans)
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?