Codeforces Round #584 - Dasha Code Championship - Elimination Round C問題 - Paint the Digits

Source

Codeforces Round #584 - Dasha Code Championship - Elimination Round C問題 (1250pt)
Problem description

問題概要

省略

解法

省略

cLayversion 20190914-1)のコード

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

//no-unlocked
int TEST, N;
char S[200002];
char T[200002];

int nx[10][400001];

{
  int i, j, k, r;
  
  rd(TEST);
  rep(TEST){
    rd(N,S);
    rep(i,N) S[i] -= '0';

    rep(k,10){
      nx[k][2N] = int_inf;
      for(i=2N-1;i>=0;i--){
        nx[k][i] = nx[k][i+1];
        if(S[i%N]==k) nx[k][i] = i;
      }
    }

    rep(i,N) T[i] = 0;
    i = k = 0;
    r = 1;
    for(;;){
      if(k==10 || r > 2) break;
      if(nx[k][i]==int_inf) k++, continue;
      j = nx[k][i] % N;
      if(T[j]) k++, continue;
      if(nx[k][i] >= N) r++;
      if(r > 2) break;
      T[j] = r;
      i = j + 1;
      if(i >= N) i-=N, r++;
    }
    
    rep(i,N) if(T[i]==0) break;
    if(i<N) wt("-"), continue;

    rep(i,N) T[i] += '0';
    T[N] = '\0';
    wt(T);
  }
}

Current time: 2022年05月18日09時42分24秒
Last modified: 2019年09月15日12時53分29秒 (by laycrs)
Tags: Competitive_Programming_Incomplete Codeforces CF584
トップページに戻る

Logged in as: unknown user (not login)

ログイン: