Submission #551655

#TimeUsernameProblemLanguageResultExecution timeMemory
551655Theo830Paint By Numbers (IOI16_paint)C++17
100 / 100
1010 ms95400 KiB
#include <bits/stdc++.h> using namespace std; typedef int ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training #include "paint.h" ll ans[200005] = {0}; ll n,k; string S; vector<int>C; int dp[200001][101]; int Next[200005]; ll exo[200005] = {0}; int solve(ll idx,ll p){ if(idx == n){ return (p == k); } if(dp[idx][p] != -1){ return dp[idx][p]; } bool ok = 0; if(S[idx] == '_'){ ok = solve(idx + 1,p); ans[idx] |= ok; return dp[idx][p] = ok; } if(p != k){ if(idx + C[p] > n){ ok = 0; } else if(idx + C[p] == n){ if(Next[idx] >= n){ ok = solve(idx + C[p],p + 1); if(ok){ exo[idx]++; exo[idx + C[p]]--; } } else{ ok = 0; } } else{ if(Next[idx] >= idx + C[p] && S[idx + C[p]] != 'X'){ ok = solve(idx + C[p] + 1,p + 1); if(ok){ exo[idx]++; exo[idx + C[p]]--; ans[idx + C[p]] = 1; } } else{ ok = 0; } } } else{ if(S[idx] == 'X'){ return dp[idx][p] = 0; } } if(S[idx] == '.'){ bool v = solve(idx + 1,p); ans[idx] |= v; ok |= v; } return dp[idx][p] = ok; } std::string solve_puzzle(std::string s, std::vector<int> c){ n = s.size(); k = c.size(); S = s; C = c; Next[n-1] = INF; for(ll i = n-2;i >= 0;i--){ Next[i] = Next[i+1]; if(s[i+1] == '_'){ Next[i] = i+1; } } memset(dp,-1,sizeof dp); solve(0,0); string res = ""; ll cur = 0; f(i,0,n){ cur += exo[i]; if(cur){ ans[i] |= 2; } } f(i,0,n){ assert(ans[i]); if(ans[i] == 3){ res += "?"; } else if(ans[i] == 2){ res += "X"; } else{ res += "_"; } } return res; } /* const int S_MAX_LEN = 200 * 1000; char buf[S_MAX_LEN + 1]; int main() { assert(1 == scanf("%s", buf)); std::string s = buf; int c_len; assert(1 == scanf("%d", &c_len)); std::vector<int> c(c_len); for (int i = 0; i < c_len; i++) { assert(1 == scanf("%d", &c[i])); } std::string ans = solve_puzzle(s, c); printf("%s\n", ans.data()); return 0; } */
#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...