Codeforces Round #598 DIV3 D問題 - Binary String Minimizing

Source

Codeforces Round #598 DIV3 D問題
Problem description

問題概要

省略

解法

省略

cLayversion 20191110-1)のコード

C++に変換後のコードはこちら

//no-unlocked
int N; ll K;
char S[1000002];
char res[1000002]; int ress;
{
  int one;
  REP(rd_int()){
    rd(N,K,S);
    one = ress = 0;
    rep(i,N){
      if(K==0) res[ress++] = S[i], continue;
      if(S[i]=='1') one++, continue;
      if(K > one){
        res[ress++] = S[i];
        K -= one;
      } else {
        rep(one-K) res[ress++] = '1';
        res[ress++] = '0';
        rep(K) res[ress++] = '1';
        K = 0;
        one = 0;
      }
    }
    rep(one) res[ress++] = '1';
    res[ress] = '\0';
    wt(res);
  }
}

Current time: 2021年11月29日18時39分38秒
Last modified: 2019年11月10日22時39分26秒 (by laycrs)
Tags: Competitive_Programming_Incomplete Codeforces CF598 CF_Div3_D
トップページに戻る

Logged in as: unknown user (not login)

ログイン: