# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1035806 |
2024-07-26T16:13:34 Z |
ReLice |
Wiring (IOI17_wiring) |
C++17 |
|
53 ms |
10672 KB |
#include "wiring.h"
#include <bits/stdc++.h>
#define ll int
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e9;
const ll mod=1e9+7;
const ll N=3e5+7;
const ld eps=1e-9;
long long dp[N];
vll r,b,v;
ll c[N];
ll pref[N],suf[N];
ll dis(ll x,ll y){
return abs(v[x]-v[y]);
}
long long min_total_length(vector<int> R, vector<int> B) {
ll i;
//setting up stuff
r=R,b=B;
for(auto i : r) v.pb(i);
for(auto i : b) v.pb(i);
r.pb(-1);
b.pb(-1);
v.pb(-1);
sort(all(r));
sort(all(b));
sort(all(v));
deque<pair<ll,ll>> seg;
for(i=1;i<(ll)v.sz;i++){
ll low=lb(all(r), v[i]) - r.begin();
if(low < (ll)r.sz && r[low] == v[i]) c[i] = 1;
if(seg.sz == 0 || c[i] != c[i - 1])seg.pb({i, i});
else seg.bc.sc=i;
}
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
while(seg.sz>1){
ll a=seg[0].fr,b=seg[0].sc,c=seg[1].fr,d=seg[1].sc;
suf[b]=0;
for(i=b-1;i>=a;i--){
suf[i]=suf[i+1]+dis(i,b);
}
for(i=a;i<=b;i++){
suf[i]+=dp[i-1];
pref[i]=(b-i+1)*dis(b,c)+suf[i];
if(i>a)chmin(pref[i],pref[i-1]);
}
for(i=b-1;i>=a;i--)chmin(suf[i],suf[i+1]);
pref[c]=0;
for(i=c;i<=d;i++){
if(i>c)pref[i]=pref[i-1]+dis(i,c);
dp[i] = pref[i] + suf[max(a, b - (i - c))] + dis(b, c) * (i - c + 1);
if(b - (i - c) - 1 >= a) chmin(dp[i], pref[i] + pref[b - (i - c) - 1]);
}
seg.pof;
}
return dp[v.sz-1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2692 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '14694' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
37 ms |
7716 KB |
3rd lines differ - on the 1st token, expected: '41596985758595', found: '-575870392' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
53 ms |
10672 KB |
3rd lines differ - on the 1st token, expected: '1068938599', found: '1152497305' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
42 ms |
9144 KB |
Output is correct |
3 |
Correct |
49 ms |
9512 KB |
Output is correct |
4 |
Correct |
47 ms |
9396 KB |
Output is correct |
5 |
Correct |
48 ms |
9652 KB |
Output is correct |
6 |
Incorrect |
1 ms |
2652 KB |
3rd lines differ - on the 1st token, expected: '42', found: '43' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2692 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '14694' |
3 |
Halted |
0 ms |
0 KB |
- |