結果

問題 No.78 クジ付きアイスバー
ユーザー latte0119latte0119
提出日時 2016-02-24 20:02:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,374 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 159,108 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-04-16 06:05:14
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,K;
string S;

int get(int k){
    int x=0,y=0;
    rep(i,k){
        if(x)x--;
        else y++;
        x+=S[i%N]-'0';
    }
    return y;
}

signed main(){
    cin>>N>>K>>S;

    if(K<10000){
        cout<<get(K)<<endl;
        return 0;
    }

    int x=0,y=0,yy=-114,yyy=-514;
    for(int i=0;true;i++){
        rep(j,N){
            if(x)x--;
            else y++;
            x+=S[j]-'0';
        }
        if(y-yy==yy-yyy){
            int tmp=K/N;
            int ans=y+(tmp-i-1)*(y-yy);
            tmp=K%N;
            rep(j,tmp){
                if(x)x--;
                else ans++;
                x+=S[j]-'0';
            }
            cout<<ans<<endl;
            return 0;
        }
        if(x>=N){
            cout<<y<<endl;
            return 0;
        }
    }
    return 0;
}
0