結果

問題 No.78 クジ付きアイスバー
ユーザー なおなお
提出日時 2014-11-26 02:07:23
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,141 bytes
コンパイル時間 3,124 ms
コンパイル使用メモリ 158,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 04:58:35
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
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 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 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--;
    }

    // あまりのあたり本数で次の箱も買える場合、無限にもらえるので最初の箱だけ考える
    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;
}
0