結果

問題 No.78 クジ付きアイスバー
ユーザー tottoripapertottoripaper
提出日時 2014-12-09 22:18:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,210 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 39,952 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 19:22:33
合計ジャッジ時間 1,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <algorithm>

typedef long long ll;

int main(){
    int N, K;
    scanf("%d %d", &N, &K);

    char ice[100];
    scanf("%s", ice);

    for(int i=N;i<2*N;i++){ice[i] = ice[i-N];}

    bool bought[100];
    std::fill(bought, bought+2*N, false);
    int cost[100], last = 0;
    std::fill(cost, cost+2*N, 0);
    
    for(int i=0;i<2*N;i++){
        if(!bought[i]){
            cost[i] = 1;
        }
        
        if(ice[i] == '1'){
            if(last+1 < 2*N){bought[last+1] = true; last += 1;}
        }else if(ice[i] == '2'){
            if(last+1 < 2*N){bought[last+1] = true; last += 1;}
            if(last+1 < 2*N){bought[last+1] = true; last += 1;}
        }

        last = std::max(i+1, last);
    }

    for(int i=1;i<N;i++){
        cost[i] += cost[i-1];
        cost[i+N] += cost[i-1+N];
    }

    // for(int i=0;i<2*N;i++){
    //     printf("%d: %d\n", i, cost[i]);
    // }

    ll res;
    if(K <= N){
        res = cost[K-1];
    }else{
        res = cost[N-1];
        K -= N;
        res += 1ll * cost[2*N-1] * (K/N);
        K %= N;
        res += K>0?cost[K-1+N]:0;
    }

    printf("%d\n", res);
}
0