QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236366 | #3033. Harry Potter and the Palindromic Radius | ahsoltan# | 0 | 0ms | 0kb | C++20 | 2.5kb | 2023-11-03 21:42:43 | 2023-11-03 21:42:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define x first
#define y second
#define ir(x,a,b) ((a) <= (x) && (x) <= (b))
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define foru(i, n) for (int i = 0; i < n; ++i)
#define fori(i,a,n) for (int i = a; i < n; ++i)
// #ifdef LOCAL
// auto& operator<<(auto&, pair<auto, auto>);
// template<typename T, typename = T::value_type>
// auto& operator<<(auto& o, T x) requires (!same_as<T, string>) {
// o << "{";
// string s;
// for (auto i : x) {
// o << s << i;
// s << ", ";
// }
// return o << "}";
// }
// auto& operator<<(auto& o, pair<auto, auto> p) {
// return o << "(" << p.first << ", " << p.second << ")";
// }
// #define debug(x..) cerr << "["#x"]:",[](auto...$){((cerr<<" "<<$),...)<<endl;}(x)
// #else
// #define debug(...) 2137
// #endif
const int N = 1000100;
int n;
vector<pair<int, int>> adj[N];
bool vis[N];
int x[N];
void neq(int a, int b) {
adj[a].push_back({b, 1});
adj[b].push_back({a, 1});
}
void eq(int a, int b) {
adj[a].push_back({b, 0});
adj[b].push_back({a, 0});
}
bool dfs(int u) {
vis[u] = true;
for (auto [v, xx] : adj[u]) {
if (!vis[v]) {
x[v] = x[u] ^ xx;
if (!dfs(v)) {
return false;
}
} else if ((x[u] ^ xx) != x[v]) {
return false;
}
}
return true;
}
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
adj[i].clear();
}
int l = 0, r = 0;
foru (i, n) {
int x;
cin >> x;
if (i-x > 0 && i+x < n-1) neq(i-x-1, i+x+1);
if (x + i > r) {
//cerr << x << " " << i << " " << r << endl;
for (int j = max(i+1, r+1), k = i-(j-i); j <= i + x; ++j, --k) {
eq(j, k);
}
r = i + x, l = i - x;
}
}
for (int i = 0; i < n; i++) {
vis[i] = false;
x[i] = 0;
}
vector<int> v;
for (int i = 0; i < n; i++) {
if (!vis[i]) {
if (!dfs(i)) {
cout << 0 << '\n';
return;
}
v.push_back(i);
}
}
cout << (1 << ssize(v)) << '\n';
for (int msk = 0; msk < 1 << ssize(v); msk++) {
for (int i = 0; i < n; i++) {
x[i] = 0;
vis[i] = false;
}
for (int i = 0; i < ssize(v); i++) {
x[v[i]] = (msk >> (ssize(v) - 1 - i)) & 1;
assert(dfs(v[i]));
}
string s(n, '0');
for (int i = 0; i < n; i++) {
s[i] = x[i] + '0';
}
cout << s << '\n';
}
/*for (int i : v) {
cerr << i << ' ';
}
cerr << '\n';*/
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
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...