AtCoder過去問精選10問をPythonで解きました。

本当は AtCoder 版!蟻本 (初級編) - Qiita を解こうと思ったのですが、つらかったので先に過去問精選10問をやりました。

AtCoder に登録したら次にやること ~ これだけ解けば十分闘える!過去問精選 10 問 ~ - Qiita

第 1 問: ABC 086 A - Product (100 点)

a, b = map(int, input().split())
if (a*b)%2 ==0:
    print('Even')
else:
    print('Odd')

 

第 2 問: ABC 081 A - Placing Marbles (100 点)

S = list(input())
print(S.count('1'))

第 3 問: ABC 081 B - Shift Only (200 点)

昔の問題(3.4.3)ではgcdはfractionsからimport する。
Python3.8ではmath からimport する。

N = int(input())
A = [int(i) for i in input().split()]
import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
tmp =gcd_list(A)
for i in range(100):
    if tmp == 2**i:
        print(i)
        break

第 4 問: ABC 087 B - Coins (200 点)

A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt = 0
for a in range(0,A+1):
    for b in range(0,B+1):
        for c in range(0,C+1):
            if a * 500 + b * 100 + c * 50 ==X:
                cnt+=1
print(cnt)

第 5 問: ABC 083 B - Some Sums (200 点)

N,A,B= map(int,input().split())
cnt = 0
for n in range(1,N+1):
    tmp = sum([int(i) for i in str(n)])
    if A<=tmp and tmp <= B:
        cnt+=n
print(cnt)

第 6 問: ABC 088 B - Card Game for Two (200 点)

N = int(input())
A = [int(a) for a in input().split()]
 
A= sorted(A,reverse=True)
Alice = 0
Bob = 0
for i in range(N):
    if i%2==0:
        Alice+=A[i]
    else:
        Bob+=A[i]
print(Alice-Bob)

第 7 問: ABC 085 B - Kagami Mochi (200 点)

N = int(input())
MOCHI=[]
for n in range(N):
    MOCHI.append(int(input()))
print(len(set(MOCHI)))

第 8 問: ABC 085 C - Otoshidama (300 点)

N,Y= map(int,input().split())
for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if i * 10000 + j *5000 + k *1000 ==Y:
            print(str(i)+" "+str(j)+" "+str(k))
            exit()
print("-1 -1 -1")

第 9 問: ABC 049 C - Daydream (300 点)

S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    cnt = 0
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
            cnt+=1
    if cnt ==0:
        print('NO')
        exit()
            
    if len(S2)<=7:
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')
# C - 白昼夢
S = input()
S2 = S
W_L = ["dream","dreamer","erase","eraser"]
while True:
    cnt = 0
    for w in W_L:
        if S2.endswith(w):
            S2 = S2[:-(len(w))]
            cnt+=1
    if cnt ==0:
        print('NO')
        exit()
            
    if len(S2)<=7:
        break
    
if S2 ==''or S2 in W_L:
    print('YES')
else:
    print('NO')

第 10 問: ABC 086 C - Traveling (300 点)

N = int(input())
T = []
for n in range(N):
    T.append([int(i) for i in input().split()])
now_t = 0
now_x = 0
now_y = 0
cnt=0
for t in T:
    if t[0]%2 !=(t[1]+t[2])%2:
        print('No')
        exit()
        
    if t[0] -now_t  >= abs(t[1]-now_x)+abs(t[2]-now_y):
        now_t = t[0]
        now_x = t[1]
        now_y = t[2]
    else:
        print('No')
        exit()
print('Yes')