QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505286#3033. Harry Potter and the Palindromic RadiusIBory0 0ms0kbC++201.9kb2024-08-05 01:07:412024-08-05 01:07:42

Judging History

This is the latest submission verdict.

  • [2024-08-05 01:07:42]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-08-05 01:07:41]
  • Submitted

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);
			}
			else {
				if (i - A[i] < 1) F = 1;
				if (i + A[i] > N) F = 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;
}

Details

Tip: Click on the bar to expand more detailed information

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
0
4
00
01
10
11
0
4
00
01
10
11
0
4
00
01
10
11
0
4
000
010
101
111
0
4
001
011
100
110
4
000
010
101
111
4
000
010
101
111
0
4
001
011
100
110
0
4
001
011
100
110
0
4
000
010
101
111
0
4
001
011
100
110
0
4
000
010
101
111
0
4
0000
0101
1010
1111
0
4
0010
0111
1000
1101
0
4
0001
0100
...

result: