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 1 year has passed since last update.

ABC 297 備忘録

Posted at

概要

 今回はABC297(2023年4月9日21:00 ~ 22:40)の参加記録について自分の実装と感想を記していこうと思う。

A問題

ポイント

  • 直前のクリック時間を記録しておく
  • 1回目のクリックだけは直前のクリックがないので、別の処理を行う
  • 条件を満たした時点でプログラムを終了させる

自分の実装

ABC_297_A.py
N, D = map(int,input().split())

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

ans = -1

last_click = 0

i = 1

for present_click in T:
    if i == 1:
        last_click = present_click
    elif present_click - last_click <= D:
        print(present_click)
        exit()
    last_click = present_click
    i += 1

print(-1)

B問題

ポイント

  • リストで入力文字列を格納
  • 格納した文字列をインデックスで各々条件分岐で判断

自分の実装

ABC_297_B.py
S = list(input())

B_index = []

K_index = []

R_index = []

for i in range(8):
    if S[i] == 'B':
        B_index.append(i+1)
    elif S[i] == 'K':
        K_index.append(i+1)
    elif S[i] == 'R':
        R_index.append(i+1)
        
if B_index[0] % 2 == B_index[1] %2 or K_index[0] < R_index[0] or K_index[0] > R_index[1]:
    print('No')
    exit()
else:
    print('Yes')

C問題

ポイント

  • 列ごとにTの文字が連続している箇所があるかどうかを確認
  • 連続箇所があった直後の場合のTを巻き込まないようにするためにboolで直前の文字列の変換の有無を判断

自分の実装

ABC_297_C.py
H, W = map(int,input().split())

S = list(input() for i in range(H))

new_S = []

changed = False

for line in S:
    last_letter = ''
    new_S_line = []
    for i in range(W):
        if changed == False and last_letter == 'T' and line[i] == 'T':
            new_S_line[-1] = 'P'
            new_S_line.append('C')
            changed = True
        else:
            new_S_line.append(line[i])
            changed = False
            last_letter = line[i]
    new_S.append(''.join(new_S_line))

for new_line in new_S:
    print(new_line)

D問題

ポイント

  • 問題文通りに従って逐一割り算をすると計算量がオーバーするので、割る回数を割り算の商と余りを考えることで短縮

自分の実装

ABC_297_D.py
import math

A, B = map(int,input().split())

ans = 0

if A < B:
    A, B = B, A
while B>0:
    ans += A//B
    A%=B
    A, B = B, A

print(ans-1)

自分の感想

 今回はC問題までしか解けなかった。D問題は記事に書いた通りの簡潔な方法が時間内に思いつかなかった。互いの数字の最大公約数で割ってやればフィボナッチ数となるはずだと考えてごちゃごちゃやってみたがうまくいかなかった。

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?