Submission #438953

#TimeUsernameProblemLanguageResultExecution timeMemory
438953adamjinweiPaint By Numbers (IOI16_paint)C++14
10 / 100
2053 ms460 KiB
#include <bits/stdc++.h> #include "paint.h" #define inf 1000000007 #define mod 1000000007 #define rnd() rand_num() #define bigrnd() dis(rand_num) //#pragma GCC optimize("Ofast","inline","-ffast-math") //#pragma GCC target("avx,sse2,sse3,sse4,mmx") //#define int long long using namespace std; unsigned sed=std::chrono::system_clock::now().time_since_epoch().count(); mt19937 rand_num(sed); uniform_int_distribution<long long> dis(0,inf); template <typename T> void read(T &x){ x=0;char ch=getchar();int fh=1; while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();} while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); x*=fh; } template <typename T> void write(T x) { if (x<0) x=-x,putchar('-'); if (x>9) write(x/10); putchar(x%10+'0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n,k; int c[105]; char s[200005]; int id[105]; int cnt[200005][2]; bool app[200005]; void dfs(int x,int y) { if(y>k) { memset(app,0,sizeof(app)); for(int i=1;i<=k;++i) for(int j=id[i];j<=id[i]+c[i]-1;++j) app[j]=1; bool flag=true; for(int i=1;i<=n;++i) if((app[i]&&s[i]=='_')||(!app[i]&&s[i]=='X')) { flag=false; break; } if(!flag) return; memset(app,0,sizeof(app)); for(int i=1;i<=k;++i) for(int j=id[i];j<=id[i]+c[i]-1;++j) { cnt[j][1]++; app[j]=1; } for(int i=1;i<=n;++i) if(!app[i]) cnt[i][0]++; return; } if(x>n) return; for(int i=x;i<=n;++i) if(i+c[y]<=n||(y==k&&i+c[y]-1<=n)) { bool flag=true; for(int j=i;j<=i+c[y]-1;++j) if(s[j]=='_') flag=false; if(s[i+c[y]]=='X'&&i+c[y]<=n) flag=false; if(flag) { id[y]=i; dfs(i+c[y]+1,y+1); } } } string solve_puzzle(string S,vector<int> C) { n=S.size(); k=C.size(); for(int i=1;i<=k;++i) c[i]=C[i-1]; for(int i=1;i<=n;++i) s[i]=S[i-1]; dfs(1,1); string ans; for(int i=1;i<=n;++i) if(cnt[i][0]!=0&&cnt[i][1]==0) ans+="_"; else if(cnt[i][0]==0&&cnt[i][1]!=0) ans+="X"; else ans+="?"; return ans; }
#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...