Submission #619978

#TimeUsernameProblemLanguageResultExecution timeMemory
619978cfalasPaint By Numbers (IOI16_paint)C++17
59 / 100
14 ms1140 KiB
#include "paint.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) #define len(x) ((int)x.size()) string solve_puzzle(string s, vector<int> c) { int n = len(s); int k = len(c); string dp[k][n]; string ans; //FOR(i,n) cout<<setw(n+2)<<i; cout<<endl; FOR(i,n){ FOR(j,n) dp[0][i]+='Z'; FOR(j,n) if(s[j]!='.') dp[0][i][j]=s[j]; bool ok = true; if(i>=c[0]-1){ FORi(j, i-c[0]+1, i+1){ if(dp[0][i][j]=='_') ok=false; else dp[0][i][j] = 'X'; } } else ok = false; if(!ok) dp[0][i] = ""; else ans = dp[0][i]; FOR(j,len(dp[0][i])) if(dp[0][i][j]=='Z') dp[0][i][j]='_'; //cout<<setw(n+2)<<dp[0][i]; } //cout<<endl; FORi(i,1,k){ FOR(j,n){ dp[i][j] = ""; bool ok = true; if(j>c[i]) FORi(k, j-c[i]+1, j+1) if(s[k]=='_') ok = false; if(j>c[i] && s[j-c[i]]=='X') ok = false; if(j>c[i] && ok){ FOR(k,j+1) dp[i][j]+="Z"; FOR(k,c[i]) dp[i][j][j-k] = 'X'; dp[i][j][j-c[i]] = '_'; FOR(k,n-j-1) dp[i][j]+=(s[len(dp[i][j])]=='.' ? 'Z' : s[len(dp[i][j])]); bool found = false; FOR(k,j-1){ if(k+1+c[i]>j) continue; if(dp[i-1][k].empty()) continue; found = true; FOR(m, j-c[i]){ if(dp[i][j][m]=='Z') dp[i][j][m] = dp[i-1][k][m]; else if(dp[i-1][k][m]!=dp[i][j][m]) dp[i][j][m] = '?'; } } if(!found) dp[i][j] = ""; else FOR(k,n) if(dp[i][j][k]=='Z') dp[i][j][k]='_'; } if(len(dp[i][j])) ans = dp[i][j]; /* bool rr = false; else rr = true, dp[i][j]=(stringstream()<<i<<" "<<j).str(); cout<<setw(n+2)<<dp[i][j]; if(rr) dp[i][j] = "";*/ } //cout<<endl; } FOR(z,n){ if(dp[k-1][z].empty()) continue; FOR(m, n){ if(dp[k-1][z][m]!=ans[m]) ans[m] = '?'; //else cout<<m; } //cout<<setw(j+3)<<dp[i][j]; } FOR(i,n) if(ans[i]=='Z') ans[i]='_'; 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...