結果

問題 No.78 クジ付きアイスバー
ユーザー sugarrrsugarrr
提出日時 2018-07-22 23:25:18
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,428 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 78,372 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 05:26:23
合計ジャッジ時間 2,068 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


//////////////////////////////////////

int main(){

    int n,k;cin>>n>>k;
    char s[n+1];cin>>s;
    
    int a1=0,b1=0,a2=0,b2=0;
    rep(i,0,n-1){
        if(a1==0){
            b1++;
        }else{
            a1--;
        }
        
        if(s[i]=='1')a1+=1;
        else if(s[i]=='2')a1+=2;
    
    }
    a2=a1;
    rep(i,0,n-1){
        if(a2==0){
            b2++;
        }else{
            a2--;
        }
        if(s[i]=='1')a2+=1;
        else if(s[i]=='2')a2+=2;
    }
    
    int ans=0;
    int a=0;
    if(n<=k){
        ans+=b1;
        ans+=(k-n)/n*b2;
        k=k%n;
        a=a1;
    }
    rep(i,0,k-1){
        if(a==0){
            ans++;
        }else{
            a--;
        }
        if(s[i]=='1')a+=1;
        else if(s[i]=='2')a+=2;
    }
    cout<<ans<<endl;
    return 0;
}
0