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;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxN=2e5+5; //make sure this is right
const int mod=1e9+7;
int good[mxN][105],good2[mxN][105],yes[mxN][105];
string solve_puzzle(string s,vector<int> c){
int k=sz(c);
int n=sz(s);
vector<int> psa(n+1);
for(int i=1;i<=n;i++)
psa[i]=psa[i-1]+(s[i-1]=='_');
queue<int> spots[k+2],pot[k+2];
spots[0].push(-1);
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
if(i-c[j-1]-1>=0 && s[i-c[j-1]-1]=='X'){
while(sz(spots[j-1]) && spots[j-1].front()<i-c[j-1])
spots[j-1].pop();
while(sz(pot[j-1]) && pot[j-1].front()<i-c[j-1])
pot[j-1].pop();
}
if(c[j-1]>i) continue;
if(i-c[j-1]-1>=0 && s[i-c[j-1]-1]=='X') continue;
if(psa[i]-psa[i-c[j-1]]>0) continue;
while(sz(pot[j-1]) && pot[j-1].front()<i-c[j-1]){
spots[j-1].push(pot[j-1].front());
pot[j-1].pop();
}
if(!sz(spots[j-1])) continue;
if(i<n && s[i]=='X') continue;
good[i][j]=1;
pot[j].push(i);
}
}
for(int i=0;i<=k;i++){
while(sz(spots[i])) spots[i].pop();
while(sz(pot[i])) pot[i].pop();
}
spots[k+1].push(n+2);
for(int i=n;i>=1;i--){
for(int j=1;j<=k;j++){
if(i+c[j-1]-1<n && s[i+c[j-1]-1]=='X'){
while(sz(spots[j+1]) && spots[j+1].front()>i+c[j-1])
spots[j+1].pop();
while(sz(pot[j+1]) && pot[j+1].front()>i+c[j-1])
pot[j+1].pop();
}
if(i+c[j-1]-1>n) continue;
if(i+c[j-1]<=n && s[i+c[j-1]-1]=='X') continue;
if(psa[i+c[j-1]-1]-psa[i-1]>0) continue;
while(sz(pot[j+1]) && pot[j+1].front()>i+c[j-1]){
spots[j+1].push(pot[j+1].front());
pot[j+1].pop();
}
if(!sz(spots[j+1])) continue;
if(i>=2 && s[i-2]=='X') continue;
good2[i][j]=1;
pot[j].push(i);
}
}
vector<int> all(n+2);
vector<int> lft,rt;
set<int> can[n+1];
for(int i=1;i<=k;i++){
vector<int> sum(n+2);
int tot=0;
for(int j=c[i-1];j<=n;j++){
if(good[j][i] && good2[j-c[i-1]+1][i]){
tot++;
sum[j-c[i-1]+1]++; sum[j+1]--;
lft.pb(j-c[i-1]+1);
rt.pb(j);
}
}
for(int j=1;j<=n;j++){
if(sum[j]) can[j].insert(i);
}
}
vector<int> always(n+2);
sort(lft.begin(),lft.end());
sort(rt.begin(),rt.end());
for(int i=1;i<=n;i++){
if(s[i-1]!='X') continue;
int l=*--lower_bound(lft.begin(),lft.end(),i+1);
int r=*lower_bound(rt.begin(),rt.end(),i);
always[l]++;
always[r+1]--;
}
for(int i=1;i<=n;i++){
if(sz(can[i])==0) s[i-1]='_';
else if(sz(can[i])==1) s[i-1]='X';
else s[i-1]='?';
always[i]+=always[i-1];
if(always[i]) s[i-1]='X';
deb(i,sz(can[i]));
}
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... |