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?

More than 3 years have passed since last update.

AtCoder Beginner Contest 179 参戦記

Last updated at Posted at 2020-09-19

AtCoder Beginner Contest 179 参戦記

ABC179A - Plural Form

1分半で突破. 書くだけ.

S = input()

if S[-1] != 's':
    print(S + 's')
else:
    print(S + 'es')

ABC179B - Go to Jail

1分半で突破. 書くだけ. 問題名はなんで「牢屋に行く」なんすかね.

N = int(input())

t = 0
max_run_length = 0
for _ in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        t += 1
    else:
        t = 0
    max_run_length = max(max_run_length, t)

if max_run_length >= 3:
    print('Yes')
else:
    print('No')

ABC179C - A x B + C

4分で突破. 書くだけ. 数秒くらい計算量大丈夫かなって考えはしたけど、まあC問題だし大丈夫だろうと腐った考えで PyPy で提出して AC.

N = int(input())

result = 0
for A in range(1, N + 1):
    for B in range(1, (N // A) + 1):
        C = N - A * B
        if C == 0:
            continue
        result += 1
print(result)

A×B+1≦N なら良いので、式変形して B≦(N-1)÷A となり、B の値域が一発で求まる.

N = int(input())

result = 0
for A in range(1, N + 1):
    result += (N - 1) // A
print(result)

ABC179D - Leaping Tak

突破できず. 50分くらい考えて閃いたけど、5分では実装できません.

ABC179E - Sequence Sum

36分半で突破. ループ検出題は何題か解いているので、そこまで難しいとは思わなかった. 入出力例3がなかなか合わなくてこれだけ時間がかかっていると説得力がないけど(笑).

N, X, M = map(int, input().split())

existence = [False] * M
a = []
A = X
for i in range(N):
    if existence[A]:
        break
    existence[A] = True
    a.append(A)
    A = A * A % M

try:
    loop_start = a.index(A)
except:
    loop_start = len(a)

result = sum(a[:loop_start])
N -= loop_start
if N != 0:
    a = a[loop_start:]
    loops = N // len(a)
    remainder = N % len(a)
    result += sum(a) * loops + sum(a[:remainder])
print(result)
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?