結果

問題 No.78 クジ付きアイスバー
ユーザー hiro71687khiro71687k
提出日時 2023-03-24 04:09:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,598 bytes
コンパイル時間 4,455 ms
コンパイル使用メモリ 266,768 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 19:53:25
合計ジャッジ時間 5,708 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=1444999999994;
ll mod=1000000007;
int main(){
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s+=s;
    s+=s;
    s+=s;
    vector<vector<pair<ll,ll>>>db(n,vector<pair<ll,ll>>(40));
    for (ll i = 0; i < n; i++)
    {
        ll now=1;
        ll id=i;
        for (ll j = i; j < s.size(); j++)
        {
            now-=1;
            now+=s[j]-'0';
            if (now<=0)
            {
                break;
            }
            id=j+1;
        }
        if (id-i>n)
        {
            db[i][0]={i,inf};
        }else{
            db[i][0]={(id+1)%n,id-i+1};
        }
    }
    for (ll i = 1; i < 40; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            db[j][i]={db[db[j][i-1].first][i-1].first,db[db[j][i-1].first][i-1].second+db[j][i-1].second};
        }
    }
    ll now=0;
    ll ans=0;
    vector<ll>two(42,1);
    for (ll i = 0; i < 40; i++)
    {
        two[i+1]=two[i]*2;
    }
    
    while (k>0)
    {
        for (ll i = 0; i < 40; i++)
        {
            if (db[now][i].second>k)
            {
                if (i==0)
                {
                    ans+=1;
                    k=0;
                    break;
                }else{
                    ans+=two[i-1];
                    k-=db[now][i-1].second;
                    now=db[now][i-1].first;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}
0