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<bits/stdc++.h>
using namespace std;
#define for2(a,b,c) for(int (a)=(b);(a)<(c);(a)++)
#include "paint.h"
#include <cstdlib>
const int maxn = 2e5+10;
const int maxk = 110;
int par[maxn];
bool f[maxn][maxk];
bool l[maxn][maxk]; /// 1- base for black
bool r[maxn][maxk]; /// 1- base for blackb
bool L[maxn][maxk]; /// 1- base for black
bool R[maxn][maxk]; /// 1- base for black
void solve(string &s,vector<int> &c,bool rev = 0){
int n = s.length();
int k = c.size();
for2(i,0,n){
par[i+1] = par[i] + (s[i]=='_');
}
f[0][0] = 1;
for2(i,1,n+1) for2(j,0,k+1){
f[i][j] = 0;
if(s[i-1] == '_' || s[i-1] == '.'){
f[i][j] |= f[i-1][j];
if(f[i-1][j]){
if(!rev) L[i][j] = 1;
else R[n-i+1][j] = 1;
}
}
if(!j && rev && f[i][j]){
r[n-i+1][0] = 1;
}
if( j != 0 && (s[i-1] == 'X' || s[i-1] == '.') ){
if( i >= c[j-1] && !(par[i] - par[i-c[j-1]]) && s[i-c[j-1]-1] != 'X' ){
f[i][j] |= f[i-c[j-1]-1][j-1];
// if(!rev) cout << i << ' ' << j << endl;
if(f[i-c[j-1]-1][j-1] && s[i] != 'X'){
if(!rev) l[i][j] = 1;
else r[n-i+1][j] = 1;
}
}
}
}
}
bool ww[maxn];
int bb[maxn];
string solve_puzzle(string s, vector<int> c) {
s = "__" + s + "__";
int n = s.length();
int k = c.size();
solve(s,c);
reverse(c.begin(),c.end());
reverse(s.begin(),s.end());
solve(s,c,1);
reverse(c.begin(),c.end());
reverse(s.begin(),s.end());
string ans;
for2(j,0,k+1) for(int i = n-1; i > 0; i--){
if(s[i-1] != 'X') r[i][j] |= r[i+1][j];
}
for2(i,1+2,n+1-2){
bool w,b;
int mx = 0;
w = b = 0;
for2(j,0,c.size()+1){
if(s[i-1] == '_' || s[i-1] == '.'){
if(L[i][j] && R[i][c.size()-j]) w = 1;
}
if(s[i-1] == 'X' || s[i-1] == '.'){
if(l[i][j] && r[i+2][c.size()-j] && s[i] != 'X'){
// cout << i << ' ' << j << endl;
// cout << s[i] << endl;
b = 1;
mx = max(mx,c[j-1]);
}
}
}
if(b){
// cout << i << ' ' << mx << endl;
bb[i-mx+1] ++;
bb[i+1] --;
}
if(w) ww[i] = 1;
}
int cur = 0;
for2(i,1+2,n+1-2){
cur += bb[i];
if(ww[i] && cur) ans += "?";
else if(ww[i]) ans += "_";
else ans += "X";
}
return ans;
}
Compilation message (stderr)
paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:3:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define for2(a,b,c) for(int (a)=(b);(a)<(c);(a)++)
~~~^~~~
paint.cpp:75:3: note: in expansion of macro 'for2'
for2(j,0,c.size()+1){
^~~~
# | 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... |