結果
問題 |
No.78 クジ付きアイスバー
|
ユーザー |
|
提出日時 | 2014-11-26 01:33:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,270 bytes |
コンパイル時間 | 1,350 ms |
コンパイル使用メモリ | 159,760 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-06 16:59:59 |
合計ジャッジ時間 | 2,672 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 13 WA * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define REPEAT(i, k, n) for(int(i)=(k);(i)<((k)+(n));++(i)) int dp[200]; int main(){ int N,K; cin >> N >> K; string s; cin >> s; // 箱買いしたときのあたり本数 int total = 0; REP(i,N) total += s[i]-'0'; int n = N; while(n > 1 && total){ // 購入と相殺 n--, total--; } // n=1箱買うときの購入数 total=あまりのあたり本数 // あまりのあたり本数で次の箱も買える場合、無限にもらえる if(n <= total){ cout << 1 << endl; return 0; } // そうでない場合、何箱買うかを概算で引いておく int k = max(0, (K-10000) / N); K -= N*k; // 残りのほしい数 n = total * k; // すでに持っているあたり本数 if(n >= N){ k--, n -= N; } // あとはシミュレーション int idx = 0, buy = 0; while(K > 0){ if(n > 0) n--; else buy++; int j = s[idx%N]-'0'; n += j; K--; idx++; } cout << k*N + buy << endl; return 0; }