結果
| 問題 |
No.2037 NAND Pyramid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-12 23:55:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,076 bytes |
| コンパイル時間 | 1,878 ms |
| コンパイル使用メモリ | 196,576 KB |
| 最終ジャッジ日時 | 2025-01-30 21:53:19 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 TLE * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
bool dp[2][400100];
int main() {
int n, k;
cin >> n >> k;
constexpr int B = 20;
vector<bool> v(1 << B);
rep(i, 1 << B) {
int now = i;
rep(j, B - 1) {
int nxt = 0;
rep(k, B - j - 1) { nxt |= (1 - ((now >> k & 1) & (now >> k + 1 & 1))) << k; }
now = nxt;
}
v[i] = now;
}
string s;
cin >> s;
rep(i, n) dp[0][i] = (s[i] - '0');
int x = 0;
while(n > k) {
if(n - (B - 1) >= k) {
int nn = n - (B - 1);
unsigned s = 0;
rep(i, B) s = (s << 1) + dp[x][i];
rep(i, nn) {
dp[x ^ 1][i] = v[s & ((1 << B) - 1)];
s = (s << 1) + dp[x][i + B];
}
x ^= 1;
n = nn;
} else {
rep(i, n - 1) { dp[x ^ 1][i] = (1 - (dp[x][i] & dp[x][i + 1])); }
x ^= 1;
n--;
}
}
rep(i, k) cout << dp[x][i];
cout << endl;
}