結果

問題 No.2037 NAND Pyramid
コンテスト
ユーザー siman
提出日時 2022-11-28 20:14:05
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 899 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,736 ms
コンパイル使用メモリ 150,016 KB
実行使用メモリ 9,280 KB
最終ジャッジ日時 2026-04-21 06:04:21
合計ジャッジ時間 4,730 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:22:14: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   22 |   int colors[N][3];
      |              ^
main.cpp:22:14: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N, K;
      |       ^
1 warning generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int colors[N][3];
  memset(colors, -1, sizeof(colors));

  for (int i = 0; i < N; ++i) {
    colors[i][0] = S[i] - '0';
  }
  
  for (int i = 1; i <= 2; ++i) {
    for (int j = 0; j < N - i; ++j) {
      colors[j][i] = !(colors[j][i - 1] & colors[j + 1][i - 1]);
    }
  }

  int offset = 0;
  int k = N - K;
  while (k >= 3) {
    k -= 2;
    offset += 1;
  }

  string ans = "";
  // fprintf(stderr, "k: %d\n", k);

  for (int i = 0; i < K; ++i) {
    if (colors[i + offset][k] == 0) {
      ans += '0';
    } else {
      ans += '1';
    }
  }

  cout << ans << endl;

  return 0;
}
0