Submission #966792

#TimeUsernameProblemLanguageResultExecution timeMemory
966792AmrWiring (IOI17_wiring)C++17
0 / 100
1085 ms8928 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define sz size() typedef long long ll; #define all(x) (x).begin(),(x).end() #define F first #define S second const int N = 2e5+2; ll a[N]; ll dp[N]; long long min_total_length(std::vector<int> r, std::vector<int> b) { ll n = r.sz, m = b.sz; vector<pair<ll,ll> > v; v.push_back({-1,-1}); for(int i = 0; i < r.sz; i++) v.push_back({r[i],0}); for(int i = 0; i < b.sz; i++) v.push_back({b[i],1}); sort(all(v)); ll start = 1,prevstart=1; for(int i = 1; i <= n+m; i++) { if(i==n+m||(v[i].S!=v[i+1].S)) { ll en = i; if(start==1) { for(int j = 1; j <= en; j++) dp[j] = -1; prevstart = start; start = i+1; continue; } ll allme = 0; for(int j = start; j <= en; j++) { allme+=v[j].F; ll allprev = 0; for(int k = start-1; k >= prevstart; k--) { allprev+=v[k].F; if(dp[k-1]==-1) continue; ll mm = 0; if(j-start+1>start-k) mm = -((j-start+1)-(start-k))*v[start-1].F; else mm = (start-k-(j-start+1))*v[start].F; dp[j] = max(dp[j],dp[k-1]+allme-allprev+mm); } } prevstart = start,start=i+1; } } // b r b rrrr //for(int i = 0; i <= n+m; i++) cout << dp[i] << " "; cout<< endl; return 1; 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:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < r.sz; i++) v.push_back({r[i],0});
      |                      ^
wiring.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 0; i < b.sz; i++) v.push_back({b[i],1});
      |                      ^
#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...