結果
問題 |
No.3266 岩井星人は見ずにはいられない
|
ユーザー |
![]() |
提出日時 | 2025-09-06 14:14:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 2,311 bytes |
コンパイル時間 | 359 ms |
コンパイル使用メモリ | 82,572 KB |
実行使用メモリ | 76,032 KB |
最終ジャッジ日時 | 2025-09-06 14:14:56 |
合計ジャッジ時間 | 3,516 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
N,A = map(int,input().split()) S = input() Zcnt, Ocnt = S.count("0"), S.count("1") rate = 1200 Ans = 0 nowAC = 0 if Zcnt > Ocnt: ACcnt = 0 while ACcnt != Ocnt and nowAC + Ocnt < A: ACcnt = 0 for s in S: if s == "0": rate -= 1 elif rate <= 1199: ACcnt += 1 rate += 1 nowAC += 1 Ans += N if nowAC + Ocnt >= A: while nowAC < A: for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 Ans += 1 if nowAC == A: break else: roop = (A - nowAC - 1) // Ocnt nowAC += roop*Ocnt Ans += roop*N for s in S: Ans += 1 if s == "1": nowAC += 1 if nowAC == A: break print(Ans) else: rateLog = [1200] ACLog = [] ROOP = False while not ROOP and nowAC + Ocnt < A: ACcnt = 0 for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 ACcnt += 1 Ans += N ACLog.append(ACcnt) if rate in rateLog: ROOP = True else: rateLog.append(rate) if nowAC + Ocnt >= A: while nowAC < A: for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 Ans += 1 if nowAC == A: break else: roop_start = rateLog.index(rate) roop_length = len(ACLog) - roop_start roop_AC = sum(ACLog[roop_start:]) roop = (A - nowAC - 1) // roop_AC nowAC += roop*roop_AC Ans += roop*roop_length*N while nowAC < A: for s in S: if s == "0": rate -= 1 elif rate <= 1199: rate += 1 nowAC += 1 Ans += 1 if nowAC == A: break print(Ans)