Only A and B were solved. Performance has been declining recently.
https://atcoder.jp/contests/abc179
A. Plural Form
S = input()
if S[-1] == 's':
answer = S + 'es'
else:
answer = S + 's'
print(answer)
Write according to the problem statement.
B. Go to Jail
N = int(input())
D = [tuple(map(int, input().split())) for _ in range(N)]
answer = 'No'
count = 0
for i in range(N):
if D[i][0] != D[i][1]:
count = 0
else:
count += 1
if count == 3:
answer = 'Yes'
break
print(answer)
It determines the doublet and returns `Yes``` when
count``` reaches
`3```.
C. A x B + C
N = int(input())
answer = 0
for a in range(1, N):
answer += (N-1) // a
print(answer)
Considering the restrictions, it seems that the for loop can be turned only once.
a * b + c = n
Transforma * b = n - c
Thena * b
It can be called the problem of counting the number of combinations of.
D. Leaping Tak
MOD = 998244353
N, K = map(int, input().split()) #N is the number of squares, K is the number of sections(K is 10 or less)
kukan = [tuple(map(int, input().split())) for _ in range(K)]
dp = [0] * (N+1)
dp[1] = 1
sumdp = [0] * (N+1)
sumdp[1] = 1
for i in range(2, N+1):
for l, r in kukan:
li = max(i - l, 0)
ri = max(i - r - 1, 0)
dp[i] += sumdp[li] - sumdp[ri]
dp[i] %= MOD
sumdp[i] = sumdp[i-1] + dp[i]
print(dp[N])
Normally, taking `dp``` is not in time, so use ``` dp``` and the cumulative sum
`sumdp```.
E. Sequence Sum
N, X, M = map(int, input().split())
count_memo = [-1] * 10**6 #Number of notes
num_memo = [0] #A note. 1 index.
a = X
count = 1
count_memo[a] = count
num_memo.append(a)
for i in range(1, N):
a = a**2 % M
if count_memo[a] == -1:
count += 1
count_memo[a] = count
num_memo.append(a)
else:
break
if count == N: #Total if finished before entering the cycle
answer = sum(num_memo)
else:
#Number and total until entering the cycle
count_before_cycle = count_memo[a] - 1
sum_before_cycle = sum(num_memo[:count_before_cycle+1])
#Number and total of 1 cycle
count_cycle = count - count_before_cycle
sum_cycle = sum(num_memo[count_before_cycle+1:])
#Number and total of remaining cycles
cycle_count = (N - count) // count_cycle
sum_after_cycle = sum_cycle * cycle_count
#Too many and total
remain_count = (N - count) % count_cycle
sum_remain = sum(num_memo[count_before_cycle+1:count_before_cycle+1 + remain_count])
answer = sum_before_cycle + sum_cycle + sum_after_cycle + sum_remain
print(answer)
a
Enters the cycle somewhere.
Therefore,
Recommended Posts