結果
問題 | No.78 クジ付きアイスバー |
ユーザー |
|
提出日時 | 2016-01-22 20:13:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,340 bytes |
コンパイル時間 | 644 ms |
コンパイル使用メモリ | 74,432 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 01:36:29 |
合計ジャッジ時間 | 1,759 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <set> #include <sstream> #include <utility> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <climits> using namespace std; typedef long long ll; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++) int main(int argc, char const *argv[]) { int n,k; string s; cin >>n >>k >>s; int ans=-1; if(k<=n){ //1箱目の途中で終わるのは普通にシミュレーション int b=0; //buy int st=0; //stock REP(i,k){ if(st>0) --st; else ++b; st+=s[i]-'0'; } ans=b; } else{ //とりあえず1周回すとどうなるか見る int b=0; //buy int st=0; //stock REP(i,n){ if(st>0) --st; else ++b; st+=s[i%n]-'0'; } //printf("b:%d, st:%d\n",b,st); if(b>st) b+=(k/n-1)*(b-st); else if(b<st) st+=(k/n-1)*(st-b); //printf("b:%d, st:%d\n",b,st); //最後1回 REP(i,k%n){ if(st>0) --st; else ++b; st+=s[i%n]-'0'; } //printf("b:%d, st:%d\n",b,st); ans=b; } std::cout << ans << std::endl; return 0; }