QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723329#3033. Harry Potter and the Palindromic RadiusMarkadiusz#100 ✓6176ms34312kbC++231.6kb2024-11-07 21:51:082024-11-07 21:51:09

Judging History

This is the latest submission verdict.

  • [2024-11-07 21:51:09]
  • Judged
  • Verdict: 100
  • Time: 6176ms
  • Memory: 34312kb
  • [2024-11-07 21:51:08]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...) cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...) {}
#endif

array<vector<int>, 2> manacher(vector<int> &in) {
	int n = ssize(in);
	array<vector<int>, 2> radius = {{vector<int>(n - 1), vector<int>(n)}};
	REP(parity, 2) {
		int z = parity ^ 1, L = 0, R = 0;
		REP(i, n - z) {
			int &rad = radius[parity][i];
			if (i <= R - z)
				rad = min(R - i, radius[parity][L + (R - i - z)]);
			int l = i - rad + z, r = i + rad;
			while (0 <= l - 1 && r + 1 < n && in[l - 1] == in[r + 1])
				++rad, ++r, --l;
			if (r > R)
				L = l, R = r;
		}
	}
	return radius;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int t;
	cin >> t;
	REP(tt, t) {
		int n;
		cin >> n;
		vector<int> v(n);
		REP(i, n)
			cin >> v[i];
		debug(n, v);
		vector<vector<int>> ans;
		REP(mask, 4) {
			vector<int> h(n);
			h[0] = mask & 1;
			h[1] = mask >> 1;
			debug(mask, h);
			FOR(i, 2, n - 1) {
				if (v[i - 1] == 0) {
					h[i] = h[i - 2] ^ 1;
				}
				else {
					h[i] = h[i - 2];
				}
			}
			auto a = manacher(h);
			debug(h, a);
			if (v == a[1])
				ans.emplace_back(h);
		}
		sort(ans.begin(), ans.end());
		cout << ssize(ans) << '\n';
		for (auto x : ans) {
			for (auto e : x)
				cout << e;
			cout << '\n';
		}
	}
}

详细


Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 6176ms
memory: 34312kb

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:

ok 401208 lines