QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#494492#3033. Harry Potter and the Palindromic RadiusPetroTarnavskyi#0 0ms0kbC++202.1kb2024-07-27 15:58:102024-07-27 15:58:12

Judging History

This is the latest submission verdict.

  • [2024-07-27 15:58:12]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-07-27 15:58:10]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 1 << 20;

int cntComps;
vector<PII> g[N];
int col[N];
VI comps[6];
string ans;

bool dfs(int v)
{
	comps[cntComps].PB(v);
	for (auto [to, w] : g[v])
	{
		if (col[to] == -1)
		{
			col[to] = col[v] ^ w;
			dfs(to);
		}
		if (col[to] != (col[v] ^ w))
		{
			return false;
		}
	}
	return true;
}

void solve()
{
	int n;
	cin >> n;
	VI p(n);
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]++;
	}
	FOR(i, 0, n)
	{
		if (i - p[i] + 1 < 0 || i + p[i] - 1 >= n)
		{
			cout << "0\n";
			return;
		}
	}
	FOR(i, 0, n)
		g[i].clear();
	cntComps = 0;
	FOR(i, 0, 6)
		comps[i].clear();
	fill(col, col + n, -1);
	int l = -1, r = -1;
	FOR(i, 0, n)
	{
		int cur = 0;
		if (i <= r)
			cur = min(r - i + 1, p[l + (r - i)]);
		if (cur > p[i])
		{
			cout << "0\n";
			return;
		}
		while (cur < p[i])
		{
			if (cur > 0)
			{
				g[i - cur].PB({i + cur, 0});
				g[i + cur].PB({i - cur, 0});
			}
			cur++;
		}
		if (0 <= i - cur && i + cur < n)
		{
			g[i - cur].PB({i + cur, 1});
			g[i + cur].PB({i - cur, 1});
		}
		if (i + cur - 1 > r)
		{
			r = i + cur - 1;
			l = i - cur + 1;
		}
	}
	FOR(i, 0, n)
	{
		if (col[i] == -1)
		{
			if (cntComps == 6)
			{
				cout << "0\n";
				return;
			}
			col[i] = 0;
			if (!dfs(i))
			{
				cout << "0\n";
				return;
			}
			cntComps++;
		}
	}
	cout << (1 << cntComps) << "\n";
	ans.resize(n);
	FOR(mask, 0, 1 << cntComps)
	{
		FOR(i, 0, cntComps)
		{
			int b = (mask >> (cntComps - 1 - i)) & 1;
			for (int v : comps[i])
			{
				ans[v] = (col[v] ^ b) + '0';
			}
		}
		cout << ans << "\n";
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 0
Memory 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: