結果
問題 |
No.3266 岩井星人は見ずにはいられない
|
ユーザー |
![]() |
提出日時 | 2025-08-10 13:46:14 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 3,796 ms |
コンパイル使用メモリ | 172,208 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-08-10 13:46:20 |
合計ジャッジ時間 | 4,302 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <iostream> #include <algorithm> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; //#define endl "\n"; ll N, A; string S; int main(){ cin >> N >> A; cin >> S; //1周目 ll pos = 1200; ll cnt = 0; for(int i = 0; i < N; i++){ if(S[i] == '0'){ pos -= 1; }else{ if(pos < 1200){ pos++; cnt++; if(A == cnt){ cout << i + 1 << endl; return 0; } } } } //2周目 A -= cnt; //残り ll ans = N; ll tmppos = pos; ll loopcnt = 0; for(int i = 0; i < N; i++){ if(S[i] == '0'){ tmppos -= 1; }else{ if(tmppos < 1200){ tmppos++; loopcnt++; } } } ans += ((A - 1) / loopcnt) * N; A -= ((A - 1) / loopcnt) * loopcnt; //残りを計算 for(int i = 0; i < N; i++){ ans++; if(S[i] == '0'){ pos -= 1; }else{ if(pos < 1200){ pos++; A--; if(A <= 0){ cout << ans << endl; return 0; } } } } return 0; }