結果

問題 No.2037 NAND Pyramid
ユーザー keisuke6keisuke6
提出日時 2022-08-12 23:10:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 2,903 ms
コンパイル使用メモリ 254,148 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-10-24 11:29:04
合計ジャッジ時間 6,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 TLE -
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 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int N,K;
pair<vector<int>,int> f(int n, int k, vector<int> &S, int x){
    if(n == k) return {S,x};
    vector<int> A={};
    int now = 0;
    for(int i=0;i<S.size();i++){
        if(i != 0) now++;
        if(S[i] == 1) continue;
        if(S[i] != 1 && (x+i)%2 == 1){
            if(now != 0) A.emplace_back(now);
            A.emplace_back(S[i]-1);
            now = 0;
        }
        else now += S[i]-1;
    }
    if(now != 0) A.emplace_back(now);
    return {A,1-(S[0] > 1 && x == 1)};
}
int main(){
  cin>>N>>K;
  vector<int> S={};
  for(int i=0;i<N;i++){
      char a;
      cin>>a;
      S.emplace_back(a-'0');
  }
  vector<int> T={};
  int now = 1;
  for(int i=1;i<N;i++){
      if(S[i] != S[i-1]){
          T.emplace_back(now);
          now=1;
      }
      else now++;
  }
  T.push_back(now);
  int a=S[0];
  for(int i=N;i>K;i--){
      pair<vector<int>,int> z = f(i,K,T,a);
      tie(T,a) = z;
  }
  for(int i=0;i<T.size();i++){
      for(int j=0;j<T[i];j++) cout<<(a+i)%2;
  }
  cout<<endl;
}
0