QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#123911 | #6683. Difficult Constructive Problem | batrr# | AC ✓ | 54ms | 14556kb | C++17 | 2.8kb | 2023-07-13 23:33:40 | 2023-07-13 23:33:42 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
int sum(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int mult(int a, int b) {
return 1ll * a * b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return bp(x, mod - 2);
}
void solve() {
ll n, k;
cin >> n >> k;
string s3;
cin >> s3;
ll K = k;
for (int b=0;b<2;b++)
{
k = K;
string s = s3;
if (s[0]=='?') s[0] = '0'+b;
if (s[0]!='0'+b) continue;
int y = (b+k)%2;
if (s[n-1]=='?') s[n-1] = '0'+y;
if (s[n-1]!='0'+y) continue;
vector<vector<int>> mx(n+1,vector<int>(2)), mn(n+1,vector<int>(2));
for (int i=n-1;i>=0;i--)
{
if (i==n-1)
{
mn[i][0] = mn[i][1] = 0;
mx[i][0] = mx[i][1] = 0;
if (s[i]!='?') mx[i]['1'-s[i]] = -mod, mn[i]['1'-s[i]] = mod;
continue;
}
mx[i][0] = max(mx[i+1][1]+1,mx[i+1][0]);
mx[i][1] = max(mx[i+1][0]+1,mx[i+1][1]);
mn[i][0] = min(mn[i+1][1]+1,mn[i+1][0]);
mn[i][1] = min(mn[i+1][0]+1,mn[i+1][1]);
if (s[i]!='?') mx[i]['1'-s[i]] = -mod, mn[i]['1'-s[i]] = mod;
}
int prv = -1;
if (k>=mn[0][0] and k<=mx[0][0]) prv = 0;
else
{
if (k>=mn[0][1] and k<=mx[0][1]) prv = 1;
else
{
continue;
}
}
string A;
A += '0'+prv;
for (int i=1;i<n;i++)
{
for (int b=0;b<2;b++)
{
int D = 0;
if (b!=prv) D = 1;
if (k>=mn[i][b]+D and k<=mx[i][b]+D)
{
k -= D;
prv = b;
A += '0'+b;
break;
}
}
}
cout << A << "\n";
return;
}
cout << "Impossible\n";
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << endl;
solve();
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3408kb
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: 54ms
memory: 14556kb
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