This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <cstdlib>
#include <vector>
#include <bitset>
#include <iostream>
using namespace std;
int n, k;
int pref[200010], lastBlack;
bitset<200010> dp[110];
string ans;
string solve_puzzle(string s, std::vector<int> c) {
lastBlack = -1;
int n = s.size();
ans = s;
s = "." + s;
for(int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + (s[i] == '_');
if(s[i] == 'X') lastBlack = i;
}
k = c.size();
for(int j = k - 1; j >= 0; j--){
for(int i = 1; i <= n - c[j] + 1; i++) {
if(s[i] == '_') dp[j][i] = false;
if(s[i - 1] == 'X') dp[j][i] = false;
// if(j == 1 && i == 7) cerr << pref[i + c[j] - 1] - pref[i - 1] << " " << s[i + c[j]] << " " << dp[j + 1][i + c[j] + 1] << "\n";
if(pref[i + c[j] - 1] - pref[i - 1] == 0 && (i == n - c[j] + 1 || s[i + c[j]] != 'X')) {
if(j == k - 1) dp[j][i] = lastBlack <= i + c[j] - 1;
else dp[j][i] = dp[j + 1][i + c[j] + 1];
}
}
}
int first = 1;
for(int j = 0; j < k; j++){
for(int i = 1; i <= n; i++) pref[i] = 0;
int ct = 0;
int nxt = -1;
for(int i = first; i <= n - c[j] + 1; i++) {
if(j == 0 && s[i - 1] == 'X') break;
if(dp[j][i]) pref[i]++, pref[i + c[j]]--, ct++;
if(dp[j][i] && nxt == -1) nxt = i;
// cerr << j << " " << i << ": " << dp[j][i] << "\n";
}
for(int i = 1; i <= n; i++) pref[i] += pref[i - 1];
for(int i = first; i <= n; i++){
if(pref[i] == ct) ans[i - 1] = 'X';
else if (pref[i] > 0) ans[i - 1] = '?';
else ans[i - 1] = '_';
// if(j == 0) cerr << i << ": " << pref[i] << "\n";
}
first = nxt + c[j] + 1;
}
for(int i = 0; i < n; i++) if(ans[i] == '.') ans[i] = '_';
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |