公式

E - 棒倒しゲーム/Hitting Stick Game 解説 by kyopro_friends


問題文に書かれている通りにゲームの進行をシミュレーションします。
シミュレーションを行う際には「現在が何ラウンド目の何回目の操作であり、棒は何本残っていて、\(s\) のどの位置までの操作が済んだか」の情報を持ちます。
\(R\) ラウンド終了しても \(s\) の最後までいかないケースや、逆に \(s\) が終わったが \(R\) ラウンド終了しないケース、残っている棒以上の本数を倒そうとするケースなどに注意してください。

実装例(Python)

R,N,M,L=map(int,input().split())
S=list(map(int,input().split()))

crr_round=0
crr_op=0
rest_pin=N

for s in S:
  if s>rest_pin:
    print("No")
    exit()
  rest_pin-=s
  crr_op+=1
  if crr_op==M or rest_pin==0:
    # start new round
    crr_round+=1
    crr_op=0
    rest_pin=N

if crr_round==R and crr_op==0:
  print("Yes")
else:
  print("No")

投稿日時:
最終更新: