結果
問題 | No.78 クジ付きアイスバー |
ユーザー |
![]() |
提出日時 | 2016-07-08 18:43:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 911 bytes |
コンパイル時間 | 545 ms |
コンパイル使用メモリ | 55,792 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 01:45:30 |
合計ジャッジ時間 | 1,568 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 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; } 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; }