Submission #479703

#TimeUsernameProblemLanguageResultExecution timeMemory
479703julian33Paint By Numbers (IOI16_paint)C++14
59 / 100
1 ms460 KiB
#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> ori; vector<pii> pos,pos2; for(int i=0;i<n;i++){ if(s[i]=='X') ori.pb(i+1); } vector<int> cnt(n+1),has(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]--; } } for(int j=1;j<=n;j++){ sum[j]+=sum[j-1]; if(sum[j]==tot){ deb(j); cnt[j]++; } has[j]+=sum[j]; } } for(int i=1;i<=n;i++){ // cnt[i]+=cnt[i-1]; deb(i,cnt[i]); if(has[i]==0) s[i-1]='_'; else if(cnt[i]==1) s[i-1]='X'; else s[i-1]='?'; } return s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...