Submission #240424

#TimeUsernameProblemLanguageResultExecution timeMemory
240424tleontest1Paint By Numbers (IOI16_paint)C++14
Compilation error
0 ms0 KiB
#include "paint.h" #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #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]; 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++){vis[j][1]=1;} 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++){vis[j][1]=1;} 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++){vis[j][1]=1;} //~ 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(); 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() { 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 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:38:2: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
  if(sira>=m){
  ^~
/tmp/cccODypd.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccg4TPfC.o:paint.cpp:(.text.startup+0x0): first defined here
/tmp/cccODypd.o:(.bss+0x0): multiple definition of `buf'
/tmp/ccg4TPfC.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status