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 "grader.cpp"
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
using namespace std;
const int N = (2e5 + 5);
const int inf = (1e9 + 7);
int n,m;
int b[N],w[N];
int dp[N][105];
int inv[N][105];
int u[N][3];
string ans;
string solve_puzzle(string s, vector<int> c) {
n = (int)s.size();
m = (int)c.size();
for (int i = 1; i <= n; i ++) {
b[i] = b[i - 1];
w[i] = w[i - 1];
if (s[i - 1] == 'X') b[i] ++;
if (s[i - 1] == '_') w[i] ++;
}
for (int i = 0; i <= n; i ++)
if (!b[i]) dp[i][0] = 1;
for (int j = 1; j <= m; j ++) {
for (int i = 1; i <= n; i ++) {
if (s[i - 1] == '_') dp[i][j] = dp[i - 1][j];
else if (s[i - 1] == 'X') {
if (i - c[j - 1] >= 0 && w[i] - w[i - c[j - 1]] == 0) {
if (i - c[j - 1] - 1 < 0) {
if (j - 1 == 0)
dp[i][j] = 1;
}
else {
if (s[i - c[j - 1]] != 'X')
dp[i][j] = dp[i - c[j - 1] - 1][j - 1];
}
}
}
else {
dp[i][j] |= dp[i - 1][j];
if (i - c[j - 1] >= 0 && w[i] - w[i - c[j - 1]] == 0) {
if (i - c[j - 1] - 1 < 0) {
if (j - 1 == 0)
dp[i][j] |= 1;
}
else {
if (s[i - c[j - 1]] != 'X')
dp[i][j] |= dp[i - c[j - 1] - 1][j - 1];
}
}
}
}
}
for (int i = n + 1; i <= n * 2; i ++)
inv[i][0] = 1;
for (int i = n; i >= 1; i --)
if (b[n] - b[i - 1] == 0) inv[i][0] = 1;
for (int j = 1; j <= m; j ++) {
for (int i = n; i >= 1; i --) {
if (s[i - 1] == '_') inv[i][j] = inv[i + 1][j];
else if (s[i - 1] == 'X') {
if (i + c[m - j] - 1 <= n && w[i + c[m - j] - 1] - w[i - 1] == 0 && s[i + c[m - j] - 1] != 'X')
inv[i][j] = inv[i + c[m - j] + 1][j - 1];
}
else {
inv[i][j] |= inv[i + 1][j];
if (i + c[m - j] - 1 <= n && w[i + c[m - j] - 1] - w[i - 1] == 0 && s[i + c[m - j] - 1] != 'X')
inv[i][j] |= inv[i + c[m - j] + 1][j - 1];
}
}
}
for (int j = 1; j <= n; j ++)
for (int k = 0; k <= m; k ++)
if (s[j - 1] != 'X' && dp[j - 1][k] && inv[j + 1][m - k]) u[j][1] = 1;
for (int j = 1; j <= m; j ++) {
for (int i = 1; i <= n; i ++) {
if (w[i + c[j - 1] - 1] - w[i - 1] == 0 && (i == 1 || s[i - 2] != 'X') && (s[i + c[j - 1] - 1] != 'X') && ((i == 1 && j - 1 == 0) || dp[i - 2][j - 1]) && (inv[i + c[j - 1] + 1][m - j])) {
u[i][2] ++,u[i + c[j - 1]][2] --;
}
}
}
for (int i = 1; i <= n; i ++)
u[i][2] += u[i - 1][2];
for (int j = 1; j <= n; j ++)
if (u[j][1] && u[j][2]) ans += '?';
else if (u[j][1]) ans += '_';
else ans += 'X';
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... |