Submission #986396

#TimeUsernameProblemLanguageResultExecution timeMemory
986396PyqeWiring (IOI17_wiring)C++17
100 / 100
43 ms11612 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; long long n,nn[2],ps[200069],dp[2][2][100069],inf=1e18; pair<long long,long long> a[200069]; #define mp make_pair #define fr first #define sc second long long min_total_length(vector<int> aa,vector<int> aa2) { long long i,j,ii,k,sz=aa.size(); n=sz+aa2.size(); for(i=1;i<=n;i++) { if(i<=sz) { a[i]={aa[i-1],0}; } else { a[i]={aa2[i-sz-1],1}; } } sort(a+1,a+n+1); dp[0][0][0]=inf; for(i=1;i<=n;i++) { ps[i]=ps[i-1]+a[i].fr; nn[1]++; if(i==n||a[i].sc!=a[i+1].sc) { for(j=0;j<=nn[1];j++) { k=nn[1]-j; dp[1][1][j]=dp[0][0][min(k,nn[0])]+(a[i-nn[1]+1].fr-a[i-nn[1]].fr)*k; if(k<=nn[0]) { dp[1][1][j]=min(dp[1][1][j],dp[0][1][k]); } dp[1][1][j]+=a[i].fr*j-(ps[i]-ps[i-j])+ps[i-j]-ps[i-nn[1]]-a[i-nn[1]+1].fr*k; } for(j=0;j<=nn[1];j++) { dp[1][0][j]=dp[1][1][j]; if(j) { dp[1][0][j]=min(dp[1][0][j],dp[1][0][j-1]); } } for(j=nn[1];j+1;j--) { dp[1][1][j]+=(a[i+1].fr-a[i].fr)*j; if(j<nn[1]) { dp[1][1][j]=min(dp[1][1][j],dp[1][1][j+1]); } } for(ii=0;ii<2;ii++) { for(j=0;j<=nn[1];j++) { dp[0][ii][j]=dp[1][ii][j]; } } nn[0]=nn[1]; nn[1]=0; } } return dp[0][0][0]; }
#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...