QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212869 | #6683. Difficult Constructive Problem | S_Explosion# | AC ✓ | 13ms | 5536kb | C++20 | 3.0kb | 2023-10-13 21:40:05 | 2023-10-13 21:40:05 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <cstring>
#include <vector>
#include <bitset>
#include <set>
template <typename Tp>
inline void read(Tp &x) {
x = 0;
bool f = true; char ch = getchar();
for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
x = f ? x : -x;
}
const int N = 1e5;
char s[N + 5];
int mn[N + 5][2], mx[N + 5][2], len[N + 5];
int main() {
int T;
read(T);
while (T--) {
int n, k;
read(n), read(k);
scanf("%s", s + 1);
mn[n][0] = mn[n][1] = mx[n][0] = mx[n][1] = 0;
for (int i = n - 1; i; --i) {
if (s[i] == '0' || s[i] == '?') {
if (s[i + 1] == '0') mn[i][0] = mn[i + 1][0], mx[i][0] = mx[i + 1][0];
else if (s[i + 1] == '1') mn[i][0] = mn[i + 1][1] + 1, mx[i][0] = mx[i + 1][1] + 1;
else mn[i][0] = std::min(mn[i + 1][0], mn[i + 1][1] + 1), mx[i][0] = std::max(mx[i + 1][0], mx[i + 1][1] + 1);
}
if (s[i] == '1' || s[i] == '?') {
if (s[i + 1] == '0') mn[i][1] = mn[i + 1][0] + 1, mx[i][1] = mx[i + 1][0] + 1;
else if (s[i + 1] == '1') mn[i][1] = mn[i + 1][1], mx[i][1] = mx[i + 1][1];
else mn[i][1] = std::min(mn[i + 1][0] + 1, mn[i + 1][1]), mx[i][1] = std::max(mx[i + 1][0] + 1, mx[i + 1][1]);
}
}
// for (int i = 1; i <= n; ++i) printf("%d %d %d %d\n", mn[i][0], mx[i][0], mn[i][1], mx[i][1]);
std::fill(len + 1, len + n + 1, (s[n] == '?') ? 1 : 2);
if (s[1] == '?') len[1] = 1;
int Min, Max;
if (s[1] == '0') Min = mn[1][0], Max = mx[1][0];
else if (s[1] == '1') Min = mn[1][1], Max = mx[1][1];
else Min = std::min(mn[1][0], mn[1][1]), Max = std::max(mx[1][0], mx[1][1]);
if (k >= Min && k <= Max && (k - Min) % len[1] == 0) {
int lst = 0;
if (s[n] != '?') len[1] = 2;
for (int i = 1; i <= n; ++i) {
if (s[i] == '0' || s[i] == '?') {
int cost = (i == 1) ? 0 : (lst ^ 0);
k -= cost;
if (k >= mn[i][0] && k <= mx[i][0] && (k - mn[i][0]) % len[i] == 0) {
putchar('0');
lst = 0;
continue;
}
else k += cost;
}
if (s[i] == '1' || s[i] == '?') {
int cost = (i == 1) ? 0 : (lst ^ 1);
k -= cost;
if (k >= mn[i][1] && k <= mx[i][1] && (k - mn[i][1]) % len[i] == 0) {
putchar('1');
lst = 1;
}
else k += cost;
}
}
puts("");
}
else puts("Impossible");
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3364kb
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: 13ms
memory: 5536kb
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