제출 #640591

#제출 시각아이디문제언어결과실행 시간메모리
640591ggoh전선 연결 (IOI17_wiring)C++14
0 / 100
1 ms1492 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define sz(v) ((int)(v).size()) typedef long long lint; typedef pair<int,int> pii; int rec[200002][2]; int n,m; lint D[402][202][2]; vector<pii>V; lint f(int p,int q,int r) { if(D[p][q][r]>=0)return D[p][q][r]; if(p<q)return D[p][q][r]=1e18; if(p==0)return D[p][q][r]=0; if(q==0) { D[p][q][r]=1e18; int ind=rec[p][1-V[p].second]; if(ind!=-1) { D[p][q][r]=min(D[p][q][r],abs(V[p].first-V[ind].first)+f(p-1,0,0)); lint sum=0; for(int i=1;i<=6;i++) { if(ind-i+1<=0 || V[ind-i+1].second==V[p].second)break; sum+=abs(V[ind-i+1].first-V[p].first); D[p][q][r]=min(D[p][q][r],sum+f(p-1,i,V[ind].second)); } } return D[p][q][r]; } else { if(r==V[p].second)return D[p][q][r]=f(p-1,q-1,q==1?0:r); else { int ind=p; for(int i=0;i<=q;i++) { ind=rec[ind-1][r]; if(ind==-1)break; } if(ind==-1)return D[p][q][r]=1e18; else return D[p][q][r]=f(p-1,q+1,r)+abs(V[p].first-V[ind].first); } } } lint min_total_length(vector<int> r, vector<int> b) { lint ans=0; n=sz(r),m=sz(b); for(int i=0;i<n;i++)V.push_back({r[i],0}); for(int j=0;j<m;j++)V.push_back({b[j],1}); V.push_back({-1e9,0}); sort(V.begin(),V.end()); n=sz(V)-1; rec[0][0]=rec[0][1]=-1; for(int i=1;i<=n;i++) { rec[i][0]=rec[i-1][0]; rec[i][1]=rec[i-1][1]; rec[i][V[i].second]=i; } memset(D,-1,sizeof(D)); ans=f(n,0,0); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

wiring.cpp: In function 'lint _Z1fiii.part.0(int, int, int)':
wiring.cpp:16:19: warning: array subscript -1 is below array bounds of 'lint [402][202][2]' {aka 'long long int [402][202][2]'} [-Warray-bounds]
   16 |  if(p<q)return D[p][q][r]=1e18;
      |                ~~~^
wiring.cpp:10:6: note: while referencing 'D'
   10 | lint D[402][202][2];
      |      ^
wiring.cpp: In function 'lint min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:16:19: warning: array subscript -1 is below array bounds of 'lint [402][202][2]' {aka 'long long int [402][202][2]'} [-Warray-bounds]
   16 |  if(p<q)return D[p][q][r]=1e18;
      |                ~~~^
#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...