# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1044577 |
2024-08-05T11:01:01 Z |
Hugo1729 |
Wiring (IOI17_wiring) |
C++11 |
|
28 ms |
10184 KB |
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200001]={0};
ll pref[200001]={0};
ll min_total_length(vector<int> r, vector<int> b) {
ll n=r.size(),m=b.size();
vector<pair<ll,ll>> a;
for(ll v : r)a.push_back({v,0});
for(ll v : b)a.push_back({v,1});
sort(a.begin(),a.end());
for(ll i=0;i<n+m;i++){
pref[i+1]=pref[i]+a[i].first;
}
// for(ll i=0;i<n+m;i++)cout << a[i].first << ' ';
// cout << '\n';
// for(ll i=0;i<=n+m;i++)cout << pref[i] << ' ';
// cout << '\n';
ll prev_begin=-1,prev_end=-1;
for(ll i=1;i<n+m;i++){
if(a[i].second!=a[i-1].second){
prev_begin=prev_end+1;
prev_end=i-1;
}
if(prev_begin==-1)continue;
if(prev_begin==0){
dp[i]=LLONG_MAX/4;
ll x=(prev_end-prev_begin+1),y=i-prev_end;
if(x<=y){
dp[i]=(a[prev_end].first*x-pref[prev_end+1])+(pref[i+1]-pref[prev_end+1]-a[prev_end].first*y);
// cout << i << ' ' << prev_begin << ' ' << prev_end << ' ' << "a: " << (a[prev_end].first*x-pref[prev_end+1]) << ' ' << (pref[i+1]-pref[prev_end+1]-a[prev_end].first*y) << '\n';
}else{
dp[i]=(a[prev_end+1].first*x-pref[prev_end+1])+(pref[i+1]-pref[prev_end+1]-a[prev_end+1].first*y);
// cout << i << ' ' << prev_begin << ' ' << prev_end << ' ' << "b: " << (a[prev_end+1].first*x-pref[prev_end+1]) << ' ' << (pref[i+1]-pref[prev_end+1]-a[prev_end+1].first*y) << '\n';
}
continue;
}
dp[i]=LLONG_MAX/4;
for(ll j=prev_begin;j<=prev_end;j++){
ll x=(prev_end-j+1),y=i-prev_end;
if(x<=y){
dp[i]=min(dp[i],(a[prev_end].first*x-(pref[prev_end+1]-pref[j]))+(pref[i+1]-pref[prev_end+1]-a[prev_end].first*y)+dp[j-1]);
// cout << i << ' ' << prev_begin << ' ' << prev_end << ' ' << "a: " << (a[prev_end].first*x-pref[prev_end+1]) << ' ' << (pref[i+1]-pref[prev_end+1]-a[prev_end].first*y) << '\n';
}else{
dp[i]=min(dp[i],(a[prev_end+1].first*x-(pref[prev_end+1]-pref[j]))+(pref[i+1]-pref[prev_end+1]-a[prev_end+1].first*y)+dp[j-1]);
// cout << i << ' ' << prev_begin << ' ' << prev_end << ' ' << "b: " << (a[prev_end+1].first*x-pref[prev_end+1]) << ' ' << (pref[i+1]-pref[prev_end+1]-a[prev_end+1].first*y) << '\n';
}
}
}
// cout << "\n\n";
// for(ll i=0;i<n+m;i++)cout << dp[i] << ' ';
// cout << "\n\n";
return dp[n+m-1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '21937' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
14 ms |
6852 KB |
Output is correct |
4 |
Correct |
16 ms |
9160 KB |
Output is correct |
5 |
Correct |
15 ms |
8904 KB |
Output is correct |
6 |
Correct |
22 ms |
10184 KB |
Output is correct |
7 |
Correct |
19 ms |
10164 KB |
Output is correct |
8 |
Correct |
20 ms |
10160 KB |
Output is correct |
9 |
Correct |
20 ms |
10032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
28 ms |
8364 KB |
3rd lines differ - on the 1st token, expected: '1068938599', found: '1152430536' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2648 KB |
3rd lines differ - on the 1st token, expected: '27', found: '23' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
3rd lines differ - on the 1st token, expected: '25859', found: '21937' |
2 |
Halted |
0 ms |
0 KB |
- |