Submission #60035

#TimeUsernameProblemLanguageResultExecution timeMemory
60035FedericoSAbduction 2 (JOI17_abduction2)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, char> pp; int H,W,Q; int A[50005],B[50005]; int x_,y_; int DP[2005][2005][4]; int Qx[2],Qy[2]; int D[4][2]; int x,y,d; vector<pp> V; int ans; void stampaOLD(){ for(int d=0;d<4;d++){ cout<<"D="<<d<<endl; for(int i=0;i<H;i++){ for(int j=0;j<W;j++) cout<<DP[i][j][d]<<" "; cout<<endl; } } } int F(int a, int b, int d){ //cout<<"F("<<a<<","<<b<<","<<d<<")\n"; if(a<0 or a>=W or b<0 or b>=H) return 0; if(DP[a][b][d]!=-1) return DP[a][b][d]; if(d%2==0){ if(A[b] > B[a]){ if(d==0) return DP[a][b][d]=F(a+1,b,d)+1; else return DP[a][b][d]=F(a-1,b,d)+1; } else return DP[a][b][d]=max(F(a,b+1,3),F(a,b-1,1))+1; } else{ if(A[b] < B[a]){ if(d==1) return DP[a][b][d]=F(a,b-1,d)+1; else return DP[a][b][d]=F(a,b+1,d)+1; } else return DP[a][b][d]=max(F(a+1,b,0),F(a-1,b,2))+1; } } bool comp(pp p, pp q){ int pn,qn; if(p.second=='a') pn=A[p.first]; else pn=B[p.first]; if(q.second=='a') qn=A[q.first]; else qn=B[q.first]; return pn>qn; } int main(){ cin>>H>>W>>Q; for(int i=0;i<H;i++) cin>>A[i]; for(int j=0;j<W;j++) cin>>B[j]; if(Q>1){ memset(DP,-1,sizeof(DP)); //stampaOLD(); while(Q--){ cin>>x>>y; x--; y--; swap(x,y); cout<<max(max(F(x+1,y,0),F(x,y-1,1)),max(F(x-1,y,2),F(x,y+1,3)))<<"\n"; } //stampaOLD(); return 0; } for(int i=0;i<H;i++) V.push_back({i,'a'}); for(int j=0;j<W;j++) V.push_back({j,'b'}); sort(V.begin(),V.end(),comp); //for(auto p:V)cout<<p.first<<" "<<p.second<<endl; cin>>x_>>y_; x_--; y_--; swap(x_,y_); x=x_+1; y=y_; d=0; if(!(x<0 or x>=W or x<0 or x>=H)){ Qx[0]=0; Qx[1]=W-1; Qy[0]=0; Qy[1]=H-1; D[0][0]=D[0][1]=-1; D[1][0]=D[1][1]=-1; D[2][0]=D[2][1]=-1; D[3][0]=D[3][1]=-1; for(auto r:V){ if(r.second=='a'){ if(r.first < Qy[0] or Qy[1] < r.first) continue; else if(y==r.first){ ans=max(ans,Qx[0]-x+1+max(y-Qy[0]+1+D[d][0],Qy[1]-y+1+D[d][1])); break; } else{ if(y<r.first){ D[0][1]=D[0][1]+abs(Qy[1]-r.first+1); D[2][0]=D[2][0]+abs(Qy[1]-r.first+1); D[3][] Qy[1]=r.first-1; } } } } } }

Compilation message (stderr)

abduction2.cpp: In function 'int main()':
abduction2.cpp:145:12: error: expected primary-expression before ']' token
       D[3][]
            ^