QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505285 | #3033. Harry Potter and the Palindromic Radius | IBory | 0 | 0ms | 0kb | C++20 | 1.8kb | 2024-08-05 01:04:50 | 2024-08-05 01:04:51 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 1000007;
int A[MAX], C[MAX];
vector<pii> G[MAX];
void DFS(int cur) {
for (auto [next, nd] : G[cur]) {
if (C[next] != -1) continue;
C[next] = C[cur] ^ nd;
DFS(next);
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int _T;
cin >> _T;
while (_T--) {
int N;
cin >> N;
for (int i = 1; i <= N; ++i) cin >> A[i];
for (int i = 1; i <= N; ++i) G[i].clear();
bool F = 0;
vector<pii> D;
for (int i = 1; i <= N; ++i) {
int l = i - A[i] - 1, r = i + A[i] + 1;
if (1 <= l && r <= N) {
G[l].emplace_back(r, 1);
G[r].emplace_back(l, 1);
}
}
if (F) {
cout << 0 << '\n';
continue;
}
int a = 1, b = 1;
while (a <= N) {
while (b < A[a] + 1) {
G[a + b].emplace_back(a - b, 0);
G[a - b].emplace_back(a + b, 0);
b++;
}
int k = 1;
while (a - k >= 1 && k + A[a - k] + 1 < b) k++;
a += k;
b -= k;
}
// Check Bipartite
for (int i = 1; i <= N; ++i) C[i] = -1;
int base = 0;
for (int i = 1; i <= N; ++i) {
if (C[i] != -1) continue;
C[i] = base;
DFS(i);
base += 2;
}
for (int i = 1; i <= N; ++i) for (auto [j, d] : G[i]) if ((C[i] ^ C[j]) != d) F = 1;
if (F) {
cout << 0 << '\n';
continue;
}
vector<string> ans;
int bit = base / 2;
for (int i = 0; i < (1 << bit); ++i) {
string yes(N, '0');
for (int j = 0; j < N; ++j) {
int n = C[j + 1] / 2;
if (i & (1 << n)) {
if (C[j + 1] & 1) yes[j] = '1';
else yes[j] = '0';
}
else {
if (C[j + 1] & 1) yes[j] = '0';
else yes[j] = '1';
}
}
ans.push_back(yes);
}
sort(ans.begin(), ans.end());
cout << ans.size() << '\n';
for (auto s : ans) cout << s << '\n';
}
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 0
Output Limit Exceeded
input:
131112 2 0 0 2 0 1 2 0 0 2 1 0 2 0 0 2 0 1 2 0 0 2 0 1 3 0 1 0 3 0 1 1 3 0 0 0 3 0 1 0 3 0 1 0 3 0 2 0 3 0 0 0 3 1 0 0 3 0 0 0 3 1 0 0 3 0 1 0 3 0 2 0 3 0 0 0 3 0 0 1 3 0 1 0 3 0 2 0 4 0 1 1 0 4 0 1 2 0 4 0 0 1 0 4 0 0 1 1 4 0 1 0 0 4 0 1 0 1 4 0 0 0 0 4 0 0 1 0 4 0 0 1 0 4 1 0 1 0 4 0 1 1 0 4 0 1 2...
output:
4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 0 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 000 010 101 111 0 4 001 011 100 110 4 000 010 101 111 4 000 010 101 111 4 000 010 101 111 4 001 011 100 110 0 4 001 011 100 110 0 4 000 010 101 111 4 000 010 101 111 4 001 011 100 110 0 4 000 010 10...