結果

問題 No.78 クジ付きアイスバー
ユーザー なおなお
提出日時 2014-11-26 01:29:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,224 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 158,716 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 04:56:06
合計ジャッジ時間 2,291 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;  // すでに持っているあたり本数

    // あとはシミュレーション
    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;
}
0