結果
問題 |
No.78 クジ付きアイスバー
|
ユーザー |
![]() |
提出日時 | 2016-07-08 18:42:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 925 bytes |
コンパイル時間 | 584 ms |
コンパイル使用メモリ | 55,768 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 23:29:58 |
合計ジャッジ時間 | 1,784 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 4 |
other | WA * 35 |
ソースコード
#include<iostream> #include<string> using namespace std; #define NMAX 50 int main(){ int N; long long K; string S; long long data[NMAX]; long long eatdata[NMAX]; cin>>N>>K; cin>>S; for(int i=0;i<N;i++){ long long ice=1; long long eat=0; int now=i; while(ice!=0){ ice--; ice+=S[now]-'0'; eat++; now++; if(now==N) now=0; if(eat==N+2){ eat=K; break; } } data[i]=eat; } cout<<endl; int nw=0; int c=0; int eatc=0; for(int i=0;i<N;i++) eatdata[i]=-1; while(1){ if(eatc>=K) break; if(eatdata[nw]!=-1){ break; } eatdata[nw]=c; c++; eatc+=data[nw]; nw+=data[nw]; nw%=N; } //cout<<K<<","<<eatc<<","<<c<<","<<nw<<","<<eatdata[nw]<<endl; int need=K-eatc; int scic=c-eatdata[nw]; int sci=need/N; if(eatc<K) c+=sci*scic; if(eatc<K) eatc+=sci*N; while(1){ if(eatc>=K) break; c++; eatc+=data[nw]; nw+=data[nw]; nw%=N; } cout<<c<<endl; }