結果

問題 No.78 クジ付きアイスバー
ユーザー face4face4
提出日時 2019-11-19 13:31:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,361 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 77,740 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 09:25:39
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<pair<int,int>> vp;
    vector<bool> flag(n, 0);
    int pos = 0;
    while(!flag[pos]){
        flag[pos] = true;
        int stock = 1;
        int j = 0;
        while(stock != 0 && j <= n){
            stock--;
            stock += s[(pos+j)%n]-'0';
            j++;
        }
        if(j > n){
            vp.push_back({pos, k}); // 無限
            break;
        }else{
            vp.push_back({pos, j});
            pos = (pos + j)%n;
        }
    }
    vector<pair<int,int>> loop, first;
    int ind = vp.size()-1;
    int loopN = 0;
    do{
        loopN += vp[ind].second;
        loop.push_back(vp[ind]);
    }while(vp[ind--].first != pos);
    while(ind >= 0){
        first.push_back(vp[ind--]);
    }
    reverse(loop.begin(), loop.end());
    reverse(first.begin(), first.end());
    int ret = 0;
    for(int i = 0; i < first.size(); i++){
        k -= first[i].second;
        ret++;
        if(k <= 0)  break;
    }
    if(k <= 0){
        cout << ret << endl;
        return 0;
    }
    ret += k/loopN*(loop.size());
    k %= loopN;
    for(int i = 0; k > 0 && i < loop.size(); i++){
        ret++;
        k -= loop[i].second;
    }
    cout << ret << endl;
    return 0;
}
0