Submission #240541

#TimeUsernameProblemLanguageResultExecution timeMemory
240541tleontest1Paint By Numbers (IOI16_paint)C++14
100 / 100
815 ms496980 KiB
#include "paint.h" #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") #include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define mp make_pair #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=1;i<=n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo inf = 1000000000000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 200100; const lo mod = 1000000007; lo n,m,b[li],PS[li],k,flag,t,dp[li][150],dp1[li][150],go[li]; lo cev; lo vis[li][5]; string s; vector<int> a; inline lo f(lo sira,lo kac){ lo cevv=0; if(sira>=m){ if(kac<n)return 0; return 1; } if(~dp[sira][kac])return dp[sira][kac]; if(kac>=n && s[sira]=='X')cevv=max(cev,f(m,0)); if(kac<n){ if(sira+a[kac]>m)cevv=max(cevv,f(m+1,kac)); else if(PS[sira+a[kac]-1]-PS[sira-1]!=a[kac] && s[sira]!='X')cevv=max(cevv,f(sira+1,kac)); else if(PS[sira+a[kac]-1]-PS[sira-1]==a[kac] && sira+a[kac]==m)cevv=max(cevv,f(m,kac+1)); else if(PS[sira+a[kac]-1]-PS[sira-1]==a[kac] && s[sira+a[kac]]!='X')cevv=max(cevv,f(sira+a[kac]+1,kac+1)); if(s[sira]!='X') cevv=max(cevv,f(sira+1,kac)); } else{ if(s[sira]=='X')cevv=max(cevv,f(m,0)); else cevv=max(cevv,f(sira+1,kac)); } return dp[sira][kac]=cevv; } inline void solve(lo sira,lo kac){// 1 is black 0 is white if(sira>m)return ; if(~dp1[sira][kac])return ; //~ cout<<sira<<" :; "<<kac<<endl; if(kac<n){ if(sira+a[kac]+1<m){ if(dp[sira+1+a[kac]][kac+1]==1 && PS[sira+a[kac]-1]-PS[sira-1]==a[kac] && s[sira+a[kac]]!='X'){ for(lo j=sira;j<=sira+a[kac]-1;j++){lo old=j;j=max(j,go[j]);go[old]=max(go[old],a[kac]+sira);if(j>sira+a[kac]-1)break;vis[j][1]=1;go[j]=max(j,a[kac]+sira);} vis[sira+a[kac]][0]=1; //~ cout<<sira+a[kac]<<endl; solve(sira+a[kac]+1,kac+1); } } else if(sira+a[kac]<m){ if(kac==n-1 && PS[sira+a[kac]-1]-PS[sira-1]==a[kac] && s[sira+a[kac]]!='X'){ for(lo j=sira;j<=sira+a[kac]-1;j++){lo old=j;j=max(j,go[j]);go[old]=max(go[old],a[kac]+sira);if(j>sira+a[kac]-1)break;vis[j][1]=1;go[j]=max(go[j],a[kac]+sira);} vis[sira+a[kac]][0]=1; solve(sira+a[kac]+1,kac+1); } } else if(sira+a[kac]==m){ if(kac==n-1 && PS[sira+a[kac]-1]-PS[sira-1]==a[kac]){ for(lo j=sira;j<=sira+a[kac]-1;j++){lo old=j;j=max(j,go[j]);go[old]=max(go[old],a[kac]+sira);if(j>sira+a[kac]-1)break;vis[j][1]=1;go[j]=max(j,a[kac]+sira);} //~ vis[sira+a[kac]][0]=1; solve(sira+a[kac]+1,kac+1); } } } if(s[sira]!='X' && dp[sira+1][kac]==1){ vis[sira][0]=1; solve(sira+1,kac); } if(s[sira]!='X' && kac==n && sira==m-1){ vis[sira][0]=1; solve(sira+1,kac); } dp1[sira][kac]=1; } std::string solve_puzzle(std::string ss, std::vector<int> v) { memset(dp,-1,sizeof(dp)); memset(dp1,-1,sizeof(dp1)); ss='0'+ss; v.insert(v.begin(),0); n=(int)v.size(); m=(int)ss.size(); for(int i=1;i<=m;i++)go[i]=i; a=v; s=ss; int ans=0; int ans1=0; for(int i=1;i<m;i++){ if(s[i]=='.')ans++; } for(int i=1;i<n;i++)ans1+=a[i]; if(ans==m-1 && ans>ans1*2){ string st{}; for(int i=1;i<m;i++){ st+='?'; } return st; } for(int i=1;i<m;i++){ PS[i]=PS[i-1]+(ss[i]=='_'?0:1); } f(1,1); //~ cout<<dp[2][1]<<endl; solve(1,1); string st{}; //~ cout<<m<<endl; for(int i=1;i<m;i++){ if(ss[i]=='X'){st+='X';continue;} if(ss[i]=='_'){st+='_';continue;} if(vis[i][0]==1 && vis[i][1]==1)st+='?'; else if(vis[i][0]==1)st+='_'; else if(vis[i][1]==1)st+='X'; //~ else st+='X'; } //~ cout<<s.size()<<" : ;"<<st.size(); return st; }

Compilation message (stderr)

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:36:2: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
  if(sira>=m){
  ^~
#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...