제출 #659107

#제출 시각아이디문제언어결과실행 시간메모리
659107uroskPaint By Numbers (IOI16_paint)C++14
100 / 100
247 ms88320 KiB
#include "paint.h" #define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll int #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) (ll)(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; #define maxn 200005 #define maxk 105 ll n,k; ll ps[maxn][2]; ll a[maxn]; ll v[maxk]; bool dp[maxn][maxk][2][2]; ll ok[maxn][2]; ll cnt[maxn]; string solve_puzzle(string s, vector<ll> c){ n = sz(s); k = sz(c); for(ll i = 1;i<=k;i++) v[i] = c[i-1]; for(ll i = 1;i<=n;i++){ if(s[i-1]=='X') a[i] = 1; else if(s[i-1]=='_') a[i] = 0; else a[i] = 2; } for(ll e = 0;e<=1;e++){ for(ll i = 0;i<=n;i++) for(ll j = 0;j<=k;j++) for(ll r = 0;r<=1;r++) dp[i][j][r][e] = 0; for(ll i = 0;i<=n;i++) for(ll j = 0;j<=1;j++) ps[i][j] = 0; for(ll i = 1;i<=n;i++){ for(ll j = 0;j<=1;j++) ps[i][j] = ps[i-1][j]; if(a[i]!=2) ps[i][a[i]]++; } dp[0][0][0][e] = 1; dp[0][0][1][e] = 1; for(ll i = 1;i<=n;i++){ if(ps[i][1]==0) dp[i][0][0][e] = 1; for(ll j = 1;j<=k;j++){ if(a[i]!=1) dp[i][j][0][e] = dp[i-1][j][0][e]|dp[i-1][j][1][e]; if(i-v[j]>=0&&ps[i][0]-ps[i-v[j]][0]==0) dp[i][j][1][e]|= dp[i-v[j]][j-1][0][e]; } } reverse(a+1,a+1+n); reverse(v+1,v+1+k); } for(ll i = 0;i<=n;i++) for(ll j = 0;j<=1;j++) ps[i][j] = 0; for(ll i = 1;i<=n;i++){ for(ll j = 0;j<=1;j++) ps[i][j] = ps[i-1][j]; if(a[i]!=2) ps[i][a[i]]++; } for(ll i = 1;i<=n;i++){ for(ll j = 0;j<=k;j++){ bool f = (dp[i-1][j][0][0]|dp[i-1][j][1][0])&(dp[n-i][k-j][1][1]|dp[n-i][k-j][0][1])&(a[i]!=0); ok[i][0]|=f; if(j&&i-v[j]>=0){ bool g = 1; if(n-i>=0) g = dp[n-i][k-j][0][1]; if(dp[i][j][1][0]&&g){ cnt[i+1]--; cnt[i-v[j]+1]++; } } } } for(ll i = 1;i<=n;i++) cnt[i]+=cnt[i-1]; for(ll i = 1;i<=n;i++) ok[i][1] = cnt[i]; string ans; for(ll i = 1;i<=n;i++){ if(a[i]!=2){ if(a[i]==1) ans.pb('X'); else ans.pb('_'); }else{ if(ok[i][1]&&ok[i][0]) ans.pb('?'); else if(ok[i][1]) ans.pb('X'); else ans.pb('_'); } } return ans; } /* .X........ 1 3 ..._._.... 1 3 ........ 2 3 4 .......... 2 3 4 */
#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...