Submission #420881

#TimeUsernameProblemLanguageResultExecution timeMemory
420881MDarioWiring (IOI17_wiring)C++11
0 / 100
1 ms204 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second long long min_total_length(vector<int> r, vector<int> b) { ll n=r.size(), m=b.size(), c[20]; vector<pair<ll, bool>> v; for(int i=0; i<n; i++)v.push_back({r[i], 0}); for(int i=0; i<m; i++)v.push_back({b[i], 1}); // if(r[0]<b[0]) v.push_back({0, 0}); // else v.push_back({0, 1}); sort(v.begin(), v.end()); ll dp[v.size()], a[v.size()]; c[0]=-1; c[1]=-1; dp[0]=0; a[0]=0; for(int i=1; i<v.size(); i++){ a[i]=v[i].F+a[i-1]; } for(int i=1; i<v.size(); i++){ if(v[i].S==0){ if(c[1]==-1)dp[i]=1000000000000000ll; else{ if(v[i-1].S==0){ dp[i]=a[i]-a[c[1]]-(i-c[1])*v[c[1]].F+min(dp[c[1]], dp[c[1]-1]); } else{ dp[i]=v[i].F-v[i-1].F+dp[i-2]; for(int t=i-2; v[t].S==1; t--)dp[i]=min(dp[i], v[i].F*(i-t)-(a[i-1]-a[t-1])+dp[t-1]); } } c[0]=i; } else{ if(c[0]==-1)dp[i]=1000000000000000ll; else{ if(v[i-1].S==1){ dp[i]=a[i]-a[c[0]]-(i-c[0])*v[c[0]].F+min(dp[c[0]], dp[c[0]-1]); } else{ dp[i]=v[i].F-v[i-1].F+dp[i-2]; for(int t=i-2; v[t].S==0; t--)dp[i]=min(dp[i], v[i].F*(i-t)-(a[i-1]-a[t-1])+dp[t-1]); } } c[1]=i; } } return dp[n+m]; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=1; i<v.size(); i++){
      |                  ~^~~~~~~~~
wiring.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=1; i<v.size(); i++){
      |                  ~^~~~~~~~~
#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...