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 <bits/stdc++.h>
using namespace std;
const int mxN=2e5+5, mxK=100;
int n, k, sum[mxN+1], dp3[mxN], dp4[mxN];
bool dp1[mxN][mxK+1], dp2[mxN][mxK+1];
string solve_puzzle(string s, vector<int> a) {
int n=(int)s.length(), k=(int)a.size();
for(int i=0; i<n; ++i)
sum[i+1]=sum[i]+(s[i]=='_');
dp1[0][0]=dp2[n][k]=1;
for(int i=0; i<n; ++i) {
for(int j=0; j<=k; ++j) {
if(s[i]^'X')
dp1[i+1][j]|=dp1[i][j];
if(j<k&&i+a[j]<n&&s[i+a[j]]^'X'&&sum[i]==sum[i+a[j]])
dp1[i+a[j]+1][j+1]|=dp1[i][j];
}
}
for(int i=n; i; --i) {
for(int j=0; j<=k; ++j) {
if(s[i-1]^'X')
dp2[i-1][j]|=dp2[i][j];
if(j&&i-a[j-1]>0&&s[i-a[j-1]-1]^'X'&&sum[i]==sum[i-a[j-1]])
dp2[i-a[j-1]-1][j-1]|=dp2[i][j];
}
}
for(int i=0; i<n; ++i) {
for(int j=0; j<=k; ++j)
dp3[i]|=dp1[i+1][j]&&dp2[i][j];
for(int j=0; j<k; ++j) {
if(i+a[j]<=n&&dp1[i][j]&&dp2[i+a[j]][j+1]&&sum[i+a[j]]==sum[i]) {
++dp4[i];
--dp4[i+a[j]];
}
}
dp4[i+1]+=dp4[i];
s[i]=(dp3[i]&&dp4[i]?'?':dp3[i]?'_':'X');
}
return s;
}
# | 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... |