結果
問題 |
No.3266 岩井星人は見ずにはいられない
|
ユーザー |
|
提出日時 | 2025-09-06 15:33:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 579 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 63,104 KB |
最終ジャッジ日時 | 2025-09-06 15:33:19 |
合計ジャッジ時間 | 3,385 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
n,A=map(int,input().split()) s=input() a=0 c=0 for i in range(n): if s[i]=='0': a+=1 else: if a>0: a-=1 c+=1 if c==A: print(i+1) exit() x=s.count('0') y=s.count('1') if x>=y: z=max(1,(A+y-c-1)//y-3) d=(x-y)*(z-1)+x-c A-=c*z+(y-c)*(z-1) ans=z*n else: z=max(1,(A+x-c)//x-3) d=x-c A-=c*z+(x-c)*(z-1) ans=z*n i=0 while True: if A==0: break ans+=1 if s[i%n]=='0': d+=1 else: if d>0: d-=1 A-=1 i+=1 print(ans)