Submission #581028

#TimeUsernameProblemLanguageResultExecution timeMemory
581028Koosha_mvWiring (IOI17_wiring)C++14
7 / 100
1092 ms4032 KiB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "wiring.h"

const int N=2e5+99;
const ll inf=1e15+99;

ll last[2],dp[N];
vector<pair<int,int>> A;

ll solve0(vector<pair<int,int>> now){
	if(now.size()==1) return inf;
	int cnt0=0,cnt1=0,last0=0,last1=0,ans=0;
	f(i,0,now.size()){
		if(now[i].S==0){
			cnt0++;
			last0=i;
		}
		else{
			cnt1++;
			last1=i;
		}
	}
	if(cnt0==0 || cnt1==0 || (cnt0>1 && cnt1>1)) return inf;
	int x;
	if(cnt0==1) x=last0;
	else x=last1;
	f(i,0,now.size()) ans+=abs(now[x].F-now[i].F);
	return ans;
}
ll solve1(vector<pair<int,int>> now){
	if(now[0].S==now.back().S) return inf;
	int cnt=0,ans=0,t0=0,t1;
	f(i,0,now.size()){
		if(now[i].S==now[0].S) ans-=now[i].F;
		else ans+=now[i].F;
		if(i+1<now.size() && now[i].S!=now[i+1].S){
			cnt++;
			t0=i+1;
		}
	}
	t1=now.size()-t0;
	if(cnt>1) return inf;
	if(t0>=t1){
		ans+=(t0-t1)*now[t0].F;
	}
	else{
		ans+=(t0-t1)*now[t0-1].F;
	}
	return ans;
}
ll min_total_length(vector<int> r,vector<int> b){
	last[0]=-inf,last[1]=-inf;
	int n=r.size()+b.size();
	for(auto x : r) A.pb({x,0});
	for(auto x : b) A.pb({x,1});
	A.pb({-1,-1});
	sort(all(A));
	f(i,1,A.size()){
		vector<pair<int,int>> now;
		maxm(last[A[i].S],1ll*A[i].F);
		dp[i]=inf;
		minm(dp[i],dp[i-1]+A[i].F-last[A[i].S^1]);
		ll res=0;
		f_(j,i-1,1){
			if(A[j].S==A[i].S) break;
			res+=A[i].F-A[j].F;
			minm(dp[i],dp[j-1]+res);
		}
		f_(j,i-1,0){
			now.pb(A[j+1]);
			sort(all(now));
			minm(dp[i],dp[j]+solve1(now));
		}
		
		//eror(dp[i]);
	}
	return dp[A.size()-1];
}
/*
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<pair<int,int>> now;
	//now.pb({1,0});
	//now.pb({2,0});
	//now.pb({3,1});
	//now.pb({4,1});
	//eror(solve1(now));
	//cout<<min_total_length({1,2},{3,4});
	cout<<min_total_length({1,2,3,7},{0,4,5,9,10});
}*/

Compilation message (stderr)

wiring.cpp: In function 'long long int solve0(std::vector<std::pair<int, int> >)':
wiring.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   33 |  f(i,0,now.size()){
      |    ~~~~~~~~~~~~~~              
wiring.cpp:33:2: note: in expansion of macro 'f'
   33 |  f(i,0,now.size()){
      |  ^
wiring.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   47 |  f(i,0,now.size()) ans+=abs(now[x].F-now[i].F);
      |    ~~~~~~~~~~~~~~              
wiring.cpp:47:2: note: in expansion of macro 'f'
   47 |  f(i,0,now.size()) ans+=abs(now[x].F-now[i].F);
      |  ^
wiring.cpp: In function 'long long int solve1(std::vector<std::pair<int, int> >)':
wiring.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   53 |  f(i,0,now.size()){
      |    ~~~~~~~~~~~~~~              
wiring.cpp:53:2: note: in expansion of macro 'f'
   53 |  f(i,0,now.size()){
      |  ^
wiring.cpp:56:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   if(i+1<now.size() && now[i].S!=now[i+1].S){
      |      ~~~^~~~~~~~~~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:8:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   78 |  f(i,1,A.size()){
      |    ~~~~~~~~~~~~                
wiring.cpp:78:2: note: in expansion of macro 'f'
   78 |  f(i,1,A.size()){
      |  ^
wiring.cpp:73:6: warning: unused variable 'n' [-Wunused-variable]
   73 |  int n=r.size()+b.size();
      |      ^
#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...