Submission #96925

#TimeUsernameProblemLanguageResultExecution timeMemory
96925liwiPaint By Numbers (IOI16_paint)C++11
90 / 100
2049 ms62896 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; #define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0) char _; #define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end()) #define all(a) a.begin(),a.end() #define println printf("\n"); #define readln(x) getline(cin,x); #define pb push_back #define endl "\n" #define INT_INF 0x3f3f3f3f #define LL_INF 0x3f3f3f3f3f3f3f3f #define MOD 1000000007 #define mp make_pair #define fastio cin.tie(0); cin.sync_with_stdio(0); #define MAXN 200005 #define MAXK 101 typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unordered_map<int,int> umii; typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef pair<int,pii> triple; typedef int8_t byte; mt19937 g1; int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);} ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);} ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);} ll lcm(ll a, ll b){return a*b/gcd(a,b);} ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;} ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;} int len,psa[MAXN],need[MAXN]; string res; bool forw[MAXN][MAXK],backw[MAXN][MAXK],white[MAXN],eforr[MAXN][MAXK],done[MAXK][MAXN]; bitset<MAXN> blocks[MAXK],possible; string solve_puzzle(string s, vector<int> c){ int K = (int)c.size(); len = (int)s.size(); for(int i=1; i<=len; i++){ psa[i] = psa[i-1]+(s[i-1]=='X'||s[i-1]=='.'); need[i] = need[i-1]+(s[i-1]=='X'); } for(int i=1; i<=K; i++) for(int k=1; k<=c[i-1]; k++) blocks[i][k] = true; forw[0][0] = backw[len+1][0] = true; for(int i=1; i<=len; i++){ forw[i][0] = need[i]==0; for(int k=1; k<=K; k++){ if(!(i == c[k-1] && k == 1) && i-c[k-1]-1 < 0) continue; int cur_len = c[k-1], valid = (psa[i]-psa[i-cur_len])==cur_len; if(s[i-1] != 'X') forw[i][k] = forw[i-1][k]; if(valid && ((k == 1 && need[i-cur_len] == 0) || (k != 1 && i > cur_len && s[i-cur_len-1] != 'X' && forw[i-cur_len-1][k-1]))) forw[i][k] = eforr[i][k] = true; } } for(int i=len; i>=1; i--){ backw[i][0] = need[len]-need[i-1]==0; for(int k=1; k<=K; k++){ if(!(i+c[K-k]-1 <= len && k == 1) && i+c[K-k]+1 > len) continue; int idx = K-k+1, cur_len = c[idx-1], valid = (psa[i+cur_len-1]-psa[i-1])==cur_len; if(s[i-1] != 'X') backw[i][k] = backw[i+1][k]; if(valid && ((k == 1 && (i+cur_len > len || need[len]-need[i+cur_len-1] == 0)) || (k != 1 && len-i+1 > cur_len && s[i+cur_len-1] != 'X' && backw[i+cur_len+1][k-1]))){ backw[i][k] = true; if(i >= 2 && s[i-2] != 'X' && forw[i-2][K-k] && !done[idx][i-1]){ done[idx][i-1] = true; possible|=(blocks[idx]<<(i-1)); } } } } for(int i=1; i<=len; i++) for(int k=1; k<=K;k ++) if(eforr[i][k] && ((i==len && k == K) || (s[i] != 'X' && backw[i+2][K-k])) && !done[k][i-c[k-1]]){ done[k][i-c[k-1]] = true; possible|=(blocks[k]<<(i-c[k-1])); } for(int i=1; i<=len; i++){ for(int k=0; k<=K; k++){ bool can_white = s[i-1]!='X'&&forw[i-1][k]&&backw[i+1][K-k]; if(k == 0) can_white = s[i-1]!='X'&&(need[i-1]==0)&&backw[i+1][K]; else if(k == K) can_white = s[i-1]!='X'&&forw[i-1][k]&&(need[len]-need[i-1]==0); if(can_white){ white[i] = true; break; } } } for(int i=1; i<=len; i++){ if(possible[i] && white[i]) res+="?"; else if(possible[i]) res+="X"; else res+="_"; } 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...