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];
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> ori;
vector<pii> pos;
for(int i=0;i<n;i++){
if(s[i]=='X')
ori.pb(i+1);
}
for(int i=1;i<=k;i++){
vector<int> sum(n+2);
int cnt=0;
for(int j=c[i-1];j<=n;j++){
if(good[j][i] && good2[j-c[i-1]+1][i]){
cnt++;
deb(i,j);
sum[j-c[i-1]+1]++; sum[j+1]--;
all[j-c[i-1]+1]++; all[j+1]--;
pos.pb({j,j-c[i-1]+1});
}
}
for(int j=1;j<=n;j++){
sum[j]+=sum[j-1];
if(sum[j]==cnt) {
s[j-1]='X';
}
}
}
sort(pos.begin(),pos.end());
vector<pii> other;
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int i=sz(ori)-1;i>=0;i--){
while(sz(pos) && pos.back().first>=ori[i]){
pq.push(pos.back());
pos.pop_back();
}
while(sz(pq) && pq.top().second>ori[i])
pq.pop();
other.pb({ori[i],pq.top().first});
}
for(int i=1;i<=n;i++){
all[i]+=all[i-1];
if(all[i]==0){assert(s[i-1]!='X'),s[i-1]='_';}
if(s[i-1]=='.') s[i-1]='?';
}
fill(all.begin(),all.end(),0);
for(auto &[a,b]:other){
deb(a,b);
all[a]++; all[b+1]--;
}
for(int i=1;i<=n;i++){
all[i]+=all[i-1];
if(all[i]) s[i-1]='X';
}
return s;
}
Compilation message (stderr)
paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:133:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
133 | for(auto &[a,b]:other){
| ^
# | 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... |