Submission #968653

#TimeUsernameProblemLanguageResultExecution timeMemory
968653MarwenElarbiPaint By Numbers (IOI16_paint)C++17
59 / 100
1 ms860 KiB
#include <bits/stdc++.h> #include <cstdlib> using namespace std; int n,m; int pre[105]; int suf[105]; bool ok[105][105]; bool bad[105][5005]; bool vis[105][105]; bool dp[105][105]; vector<int> nabba(105); string bahma; bool dfs(int x,int y){ //cout <<n<<" "<<m<<endl; //cout <<x<<" "<<y<<" "<<vis[x][y]<<endl; if(x>n+1) return dp[x][y]=false; if(y==m){ if(x<=n){ //cout <<x<<endl; if(suf[n]-suf[x-1]>0) return false; bad[x][n-x]=true; } return dp[x][y]=true; } if(vis[x][y]) return dp[x][y]; vis[x][y]=true; //x++; if(bahma[x]!='X'&&dfs(x+1,y)){ bad[x][0]=true; } for (int i = x; i <= n-nabba[y]; ++i) { if(suf[i-1]-suf[x-1]>0) break; if((pre[i+nabba[y]-1]-pre[i-1])==0&&(suf[i+nabba[y]]-suf[i+nabba[y]-1])==0){ //cout <<suf[10+nabba[y]]-pre[10+nabba[y]-1]<<endl; dp[i][y]|=dfs(i+nabba[y]+1,y+1); dp[x][y]|=dp[i][y]; //dp[i][y]|=dfs(i+nabba[y],y+1); //if(x==10) cout <<i<<" "<<nabba[y]<<" "<<y<<" "<<dp[x][y]<<endl; if(dp[i][y]){ ok[i][y]=true; if(i-x>0) bad[x][i-x-1]=true; bad[i+nabba[y]][0]=true; //cout <<x<<" "<<i<<" "<<y<<endl; } //cout <<x<<" "<<i<<" "<<i+nabba[y]+1<<" "<<y+1<<endl; } } //cout <<"end "<<" "<<x<<" "<<y<<" "<<dp[x][y]<<endl; return dp[x][y]; } std::string solve_puzzle(std::string s, std::vector<int> c) { //if(s=="..._._....") return "???___????"; //if(s==".X........") return "?XX?______"; m=c.size(); nabba=c; s='#'+s; bahma=s; n=s.size(); //cout <<n<<endl; for (int i = 1; i <= n; ++i) { if(s[i]=='_') pre[i]=1; else if(s[i]=='X') suf[i]=1; pre[i]+=pre[i-1]; suf[i]+=suf[i-1]; } dfs(1,0); for (int i = 1; i <= n; ++i) { for (int j = 0; j < m; ++j) { if(ok[i][j]){ //cout <<i<<" "<<j<<endl; for (int k = i; k <= i+c[j]-1; ++k) { ok[k][104]=true; } } } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if(bad[i][j]){ for (int k = i; k <= i+j; ++k) { bad[k][0]=true; } } } } string res=""; for (int i = 1; i <= n; ++i) { //cout <<res<<endl; //cout <<ok[i][0]<<" "; if(s[i]!='.') res.push_back(s[i]); else if(ok[i][104]&&bad[i][0]) res.push_back('?'); else if(ok[i][104]) res.push_back('X'); else res.push_back('_'); } return res; }
#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...