Submission #28724

#TimeUsernameProblemLanguageResultExecution timeMemory
28724repeatingPaint By Numbers (IOI16_paint)C++11
59 / 100
13 ms87376 KiB
#include <bits/stdc++.h> #include "paint.h" #define F first #define S second #define P push #define pb push_back #define MEM(dp,i) memset(dp,i,sizeof(dp)) #define W while #define R return #define C continue #define SI size() #define ll long long #define ld long double #define pll pair<ll,ll> #define pii pair<int,int> #define SF(x) scanf("%I64d",&x) #define SF2(x,y) scanf("%I64d%I64d",&x,&y) #define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z) #define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o) #define all(v) v.begin(),v.end() using namespace std; const long long INF = 1e15; const int MX=200005; vector<int> c; string s; int pr[MX]; int prb[MX]; int k,n; int dp[MX][105]; int seg(int x,int y){ if(x>y)R 0; int ret=pr[y]; if(x)ret-=pr[x-1]; R ret; } int segb(int x,int y){ if(x>y)R 0; int ret=prb[y]; if(x)ret-=prb[x-1]; R ret; } int w[MX]; int b[MX]; int DP(int x,int y){ if(y==k&&segb(x,n-1)){R 0;} if(y==k){w[x]++;R 1;} if(x>=n)R 0; int &ret=dp[x][y]; if(ret!=-1)R ret; ret=0; if(s[x]!='X'){ ret=DP(x+1,y); if(DP(x+1,y)){ w[x]++; w[x+1]--; } } if(seg(x,x+c[y]-1)==0&&x+c[y]-1<n){ ret=max(ret,DP(x+c[y]+1,y+1)); if((x+c[y]==n||s[x+c[y]]!='X')&&DP(x+c[y]+1,y+1)){ w[x+c[y]]++; w[x+c[y]+1]--; b[x]++; b[x+c[y]]--; } } // cout<<x<<" "<<y<<" "<<ret<<endl; R ret; } string solve_puzzle(string s_, vector<int> c_) { s=s_; c=c_; n=s.SI; k=c.SI; MEM(dp,-1); pr[0]=(s[0]=='_'); for(int i=1;i<n;i++){ pr[i]=pr[i-1]+(s[i]=='_'); // cout<<pr[i]; } prb[0]=(s[0]=='X'); for(int i=1;i<n;i++){ prb[i]=prb[i-1]+(s[i]=='X'); } DP(0,0); for(int i=1;i<n;i++){ b[i]+=b[i-1]; w[i]+=w[i-1]; } string res=""; for(int i=0;i<n;i++){ if(b[i]&&w[i]){ res+='?'; } else if(b[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...