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 all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define lastbit(i) __builtin_ctz(i)
const int maxn=2e5+9;
bool f[maxn][101];
bool g[maxn][101];
int s1[maxn],s2[maxn];
bool white[maxn];
bool black[maxn];
pii bl[maxn];
string solve_puzzle(string s,vector<int>c){
int n=sz(s),k=sz(c);
s=" "+s;
set<int>id;
for1(i,1,n){
s1[i]=s1[i-1],s2[i]=s2[i-1];
if (s[i]=='X'){
s1[i]++;
black[i]=1;
}
if (s[i]=='_')
{
s2[i]++;
white[i]=1;
}
if (s[i]=='.'){
id.insert(i);
}
}
f[0][0]=1;
g[n+1][k]=1;
for1(i,0,n-1){
for1(j,0,k){
if (i>0&&s[i]=='X')f[i][j]=0;
}
for1(j,0,k-1){
if (i>0&&s[i]=='X')f[i][j]=0;
if (!f[i][j])continue;
f[i+1][j]=1;
if (i+1+c[j]-1<=n&&s2[i+1+c[j]-1]-s2[i]==0){
f[i+1+c[j]][j+1]=1;
}
}
for1(j,0,k){
if (!f[i][j])continue;
f[i+1][j]=1;
}
}
for2(i,n+1,1){
for2(j,k,0){
if (i<n+1&&s[i]=='X')g[i][j]=0;
}
for2(j,k,1){
if (i<n+1&&s[i]=='X')g[i][j]=0;
if (!g[i][j])continue;
int r=i-1,l=r-c[j-1]+1;
if (l>=1&&s2[r]-s2[l-1]==0){
g[l-1][j-1]=1;
}
}
for2(j,k,0){
if (!g[i][j])continue;
g[i-1][j]=1;
}
}
for1(i,1,n){
for1(j,0,k){
if (f[i][j]&&g[i][j]){
white[i]|=1;
}
}
}
for1(i,0,n-1){
if (id.empty())continue;
while (!id.empty()&&*(id.begin())<=i){
id.erase(id.begin());
}
for1(j,0,k-1){
if (!f[i][j])continue;
//j thang dau tien
if (j+1>k||i+1+c[j]-1>n||s2[i+1+c[j]-1]-s2[i]>0)continue;
if (g[i+1+c[j]][j+1]){
int l=i+1,r=i+1+c[j]-1;
while (!id.empty()&&*(id.begin())<=r){
black[*id.begin()]=1;
bl[*id.begin()]={i,j};
id.erase(id.begin());
}
}
}
}
string temp;
for1(i,1,n){
if (black[i]&&white[i]){
temp.pb('?');
}
else if (!black[i]){
temp.pb('_');
}
else {
temp.pb('X');
}
}
return temp;
}
/*signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(".INP","r",stdin);
//freopen(".OUT","w",stdout);
string s;
cin>>s;
int k;
cin>>k;
vector<int>c;
for1(i,1,k){
int x;
cin>>x;
c.pb(x);
}
string temp=solve_puzzle(s,c);
int n=sz(s);
cout<<temp;
}*/
Compilation message (stderr)
paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:97:5: warning: unused variable 'l' [-Wunused-variable]
97 | int l=i+1,r=i+1+c[j]-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... |