QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411519#6683. Difficult Constructive Problemle0n#AC ✓10ms5004kbC++141.4kb2024-05-15 15:21:442024-05-15 15:21:44

Judging History

你现在查看的是最新测评结果

  • [2024-05-15 15:21:44]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:5004kb
  • [2024-05-15 15:21:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

char s[100005];
int sum[100005], owo[100005], pos[100005], n;
bool qry(int x, int t, int y)
{
	if(x == n + 1)
		return y == 0;
	int lo = owo[x] + (pos[x] != n + 1 && (s[pos[x]] - '0') != t);
	int ro = sum[x], d = pos[x] - x;
	if(pos[x] == n + 1)
		ro += d;
	else
		ro += d + ((d & 1) ^ (t != (s[pos[x]] - '0')));
	return (((y & 1) == (lo & 1) || s[n] == '?') && lo <= y && y <= ro);
}

int main()
{
	int t, k, d, i, j, lp;
	pair<int, int> o;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d%d", &n, &k);
		scanf("%s", s + 1);
		sum[n + 1] = 0;
		owo[n + 1] = 0;
		pos[n + 1] = n + 1;
		lp = n + 1;
		for(i = n; i >= 1; i--)
		{
			sum[i] = sum[i + 1];
			owo[i] = owo[i + 1];
			if(s[i] != '?')
			{
				if(lp == n + 1)
					sum[i] += lp - i - 1;
				else
				{
					j = lp - i - 1;
					sum[i] += j + ((j & 1) ^ (s[i] != s[lp]));
				}
				owo[i] += (lp != n + 1 && s[i] != s[lp]);
				lp = i;
			}
			pos[i] = lp;
		}
		for(i = 1; i <= n; i++)
			if(s[i] == '?')
			{
				d = k - ('0' != s[i - 1] && i > 1);
				if(qry(i + 1, 0, d))
				{
					s[i] = '0';
					k = d;
					continue;
				}
				s[i] = '1';
				k -= ('1' != s[i - 1] && i > 1);
			}
			else
				k -= (s[i] != s[i - 1] && i > 1);
		if(!k)
			printf("%s\n", s + 1);
		else
			printf("Impossible\n");
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3800kb

input:

5
9 6
1?010??01
9 5
1?010??01
9 6
100101101
9 5
100101101
9 3
????????1

output:

100100101
Impossible
100101101
Impossible
000000101

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 10ms
memory: 5004kb

input:

6110
2 0
01
9 5
????110??
18 8
???111???00??010??
11 8
001??01???0
2 0
00
8 1
?????111
11 2
110???01???
13 7
??100???01??1
6 2
?????0
18 8
110??11??011??110?
12 5
00??011??00?
20 10
??01???0011???0010??
1 0
?
13 6
???10??110??0
6 2
00???1
17 10
??010??001???11??
5 2
????0
14 7
010???00???11?
2 1
01
...

output:

Impossible
001011001
000111000000101010
00101010010
00
00000111
11000001111
0010000101001
000010
110001100011001101
000001101001
00010000011001001010
0
0001000110010
Impossible
00010010010101100
00010
01000100010111
01
0100100001
Impossible
001100010100100101
00111111000
000
01111001
001000000100010...

result:

ok 6110 lines