結果
問題 |
No.3266 岩井星人は見ずにはいられない
|
ユーザー |
![]() |
提出日時 | 2025-09-06 15:44:37 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,597 bytes |
コンパイル時間 | 3,258 ms |
コンパイル使用メモリ | 276,560 KB |
実行使用メモリ | 15,940 KB |
最終ジャッジ日時 | 2025-09-06 15:44:45 |
合計ジャッジ時間 | 7,641 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 8 TLE * 1 -- * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define ll long long const long long mod=998244353; const long long hmod=46216567629137; int main(){ cin.tie(0)->sync_with_stdio(0); cout.tie(0); ll N,A; string S; cin>>N>>A>>S; int zero=0,one=0; rep(i,N){ if(S[i]=='0') zero++; else one++; } int maximum=0; int now=0; rep(i,N){ if(S[i]=='0') now--; else now++; maximum=max(maximum,now); } ll ans=0; if(one-maximum-zero>=0){ ll cnt=(A-1)/(one-maximum); ans+=N*cnt; cnt*=(one-maximum); int now=1200; rep(i,N){ if(cnt==A) break; if(S[i]=='1'){ if(now!=1200){ now++; cnt++; } } else now--; ans++; } cout<<ans<<endl; return 0; } else{ ll now_rate=1200; ll ans=0; ll cnt=0; while(now_rate>=1200-maximum){ ans+=N; cnt+=one-(maximum-1200+now_rate); if(cnt>A){ cnt-=one-0LL,(maximum-1200+now_rate); ans-=N; break; } now_rate+=one-(maximum-1200+now_rate)-zero; } ll loop=(A-cnt-1)/one; ans+=N*loop; cnt+=loop*one; rep(i,N){ if(cnt==A) break; if(S[i]=='1'){ cnt++; } ans++; } cout<<ans<<endl; } }