Submission #240524

#TimeUsernameProblemLanguageResultExecution timeMemory
240524tleontest1Paint By Numbers (IOI16_paint)C++17
Compilation error
0 ms0 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 = 200002; const lo mod = 1000000007; int n,m,b[li],PS[li],k,flag,t,dp[li][102],dp1[li][102],go[li]; int cev; bool vis[li][5]; string s; vector<int> a; inline int f(int sira,int kac){ int 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(int sira,int 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(int j=sira;j<=sira+a[kac]-1;j++){j=max(j,go[j]);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(int j=sira;j<=sira+a[kac]-1;j++){int 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(int j=sira;j<=sira+a[kac]-1;j++){j=max(j,go[j]);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; 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; } const int S_MAX_LEN = 200 * 1000; char buf[S_MAX_LEN + 1]; int main() { //~ freopen("bbb.txt","r",stdin); //~ freopen("att.txt","w",stdout); 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; }

Compilation message (stderr)

paint.cpp: In function 'void solve(int, int)':
paint.cpp:71:99: error: expected ';' before 'if'
     for(int j=sira;j<=sira+a[kac]-1;j++){int 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);}
                                                                                                   ^~