Submission #1035822

# Submission time Handle Problem Language Result Execution time Memory
1035822 2024-07-26T16:26:29 Z ReLice Wiring (IOI17_wiring) C++17
0 / 100
1000 ms 12040 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];
long long  pref[N],suf[N];
long long dis(ll x,ll y){
	return abs(v[x]-v[y]);
}
long long min_total_length(vector<int> R, vector<int> B) {
	ll i,j;
	//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;
		pref[c]=0;
		suf[b]=0;
		for(i=c;i<=d;i++){
			if(i>c)pref[i]=pref[i-1]+dis(i,c);
			for(j=b;j>=a;j--){
				if(j<b)suf[j]=suf[j+1]+dis(j,b);
				chmin(dp[i],pref[i]+suf[j]+dp[j-1]+dis(b,c)*max(b-j+1,i-c+1));
			}
		}
		seg.pof;
	}
	
	return dp[v.sz-1];
}







# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 1 ms 2652 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 Execution timed out 1096 ms 7792 KB Time limit exceeded
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 55 ms 12040 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 2652 KB Output is correct
2 Execution timed out 1094 ms 9020 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 1 ms 2652 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -