結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-26 02:07:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,141 bytes |
| コンパイル時間 | 1,444 ms |
| コンパイル使用メモリ | 158,552 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-06 17:00:53 |
| 合計ジャッジ時間 | 2,317 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 WA * 9 |
ソースコード
#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--;
}
// あまりのあたり本数で次の箱も買える場合、無限にもらえるので最初の箱だけ考える
if(n <= total){
K -= (K-1)/N*N;
}
// 何箱買うかを概算で引いておく
int k = max(0, (K-10000) / N);
K -= N*k; // 残りのほしい数
ll m = (ll)total * k; // すでに持っているあたり本数
// あとはシミュレーション
int idx = 0, buy = 0;
while(K > 0){
if(m > 0) m--; else buy++;
int j = s[idx%N]-'0';
m += j;
K--; idx++;
}
cout << k*n + buy << endl;
return 0;
}