Submission #59852813


Source Code Expand

#if !__INCLUDE_LEVEL__
#include __FILE__



int main(){
    ll N,K;cin>>N>>K;
    string S;cin>>S;
    ll count=0;
    ll flag=0;
    ll lastOneIdx=0;
    ll lengthOne = 0;
    ll kflag = 0;
    ll kstartIdx = 0;
    rep(i,0,N){
        if(kflag == 1){
            if(S[i]=='1')lengthOne++;
            else break;
        }

        if(S[i]=='1' && flag==0){
            flag=1;
            count++;
            if(count==K){
                kflag = 1;
                lengthOne++;
                kstartIdx = i;
                continue;
            }
        }
        else if(S[i]=='0' && flag==1){
            flag=0;
            lastOneIdx = i-1;
        }
        
    }


    rep(i,0,lastOneIdx+1){
        cout<<S[i];
    }
    rep(i,lastOneIdx+1, (lastOneIdx+1+lengthOne)){
        cout<<1;
    }
    rep(i,lastOneIdx+1+lengthOne, kstartIdx+lengthOne){
        cout<<S[i-lengthOne];
    }
    rep(i,kstartIdx+lengthOne,N){
        cout<<S[i];
    }
    cout<<endl;
    return 0;
}

#else
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(13); } }init;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define rep(i, x, limit) for (int i = (int)x; i < (int)limit; i++)
#define REP(i, x, limit) for (int i = (int)x; i <= (int)limit; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el '\n'
#define spa " "
#define Yes cout << "Yes" << el
#define No cout << "No" << el
#define YES cout << "YES" << el
#define NO cout << "NO" << el
#define eps (1e-10)
#define Equals(a,b) (fabs((a) - (b)) < eps )

const double pi = 3.141592653589793238;
const int inf = 1073741823;
const ll infl = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

//配列の要素を空白区切りで出力 第二引数をtrueにすると改行区切り
template<class T> inline void print_vec(const vector<T>& v, bool split_line=false) {
    if(v.empty()){
        cout << "This vector is empty." << el;
        return;
    }
    for (int i = 0; i < v.size(); i++) {
        if(v[i]==inf || v[i]==infl) cout << 'x' << " \n"[split_line || i+1==(int)v.size()];
        else cout << v[i] << " \n"[split_line || i+1==(int)v.size()];
    }
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

#endif

Submission Info

Submission Time
Task C - Move Segment
User naok_000
Language C++ 23 (gcc 12.2)
Score 300
Code Size 2811 Byte
Status AC
Exec Time 14 ms
Memory 3864 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3580 KiB
random_01.txt AC 6 ms 3744 KiB
random_02.txt AC 6 ms 3792 KiB
random_03.txt AC 14 ms 3844 KiB
random_04.txt AC 6 ms 3788 KiB
random_05.txt AC 10 ms 3848 KiB
random_06.txt AC 6 ms 3856 KiB
random_07.txt AC 2 ms 3680 KiB
random_08.txt AC 5 ms 3660 KiB
random_09.txt AC 3 ms 3572 KiB
random_10.txt AC 6 ms 3776 KiB
random_11.txt AC 6 ms 3772 KiB
random_12.txt AC 5 ms 3804 KiB
random_13.txt AC 2 ms 3528 KiB
random_14.txt AC 6 ms 3808 KiB
random_15.txt AC 2 ms 3584 KiB
random_16.txt AC 6 ms 3616 KiB
random_17.txt AC 6 ms 3696 KiB
random_18.txt AC 6 ms 3624 KiB
random_19.txt AC 5 ms 3864 KiB
random_20.txt AC 6 ms 3788 KiB
random_21.txt AC 3 ms 3548 KiB
random_22.txt AC 6 ms 3752 KiB
random_23.txt AC 2 ms 3780 KiB
random_24.txt AC 6 ms 3624 KiB
random_25.txt AC 5 ms 3768 KiB
sample_01.txt AC 1 ms 3440 KiB
sample_02.txt AC 1 ms 3492 KiB