답안 #114775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114775 2019-06-02T16:16:13 Z faustaadp 전선 연결 (IOI17_wiring) C++17
13 / 100
1000 ms 8548 KB
#include "wiring.h"
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,i,te,d[202020];
pair<ll,ll> a[202020];
ll com(ll aa,ll bb)
{
	ll ii;
	vector<ll> x,y;
	for(ii=aa;ii<=bb;ii++)
		if(a[ii].se==a[aa].se)
			x.pb(a[ii].fi);
		else
			y.pb(a[ii].fi);
	ll H=0;
	reverse(x.begin(),x.end());
	if(x.size()<y.size())
	{
		for(ii=0;ii<x.size();ii++)
			H+=abs(x[ii]-y[ii]);
		for(ii=x.size();ii<y.size();ii++)
			H+=abs(x[0]-y[ii]);
	}
	else
	{
		for(ii=0;ii<y.size();ii++)
			H+=abs(x[ii]-y[ii]);
		for(ii=y.size();ii<x.size();ii++)
			H+=abs(y[0]-x[ii]);
	}
	//cout<<aa<<" "<<bb<<" "<<H<<"\n";
	return H;
}
ll depe(ll aa)
{
	if(aa==n+1)
		return 0;
	if(d[aa]==-1)
	{
		d[aa]=1e18;
		ll ii,udh=0;
		vector<ll> z;
		for(ii=aa;ii<=n;ii++)
		{
			if(ii>aa&&a[ii].se!=a[ii-1].se)
				udh=1;
			if(udh&&a[ii].se==a[aa].se)
				break;
			if(udh)
			{
				z.pb(ii);
				//d[aa]=min(d[aa],com(aa,ii)+min(depe(ii+1),depe(ii)));
			}
		}
		ll L=0,R=z.size()-1,C1,C2,CC1,CC2;
		while(L<=R)
		{
			C1=L+(R-L)/3;
			C2=R-(R-L)/3;
			CC1=com(aa,z[C1])+min(depe(z[C1]+1),depe(z[C1]));
			CC2=com(aa,z[C2])+min(depe(z[C2]+1),depe(z[C2]));
			if(CC1>CC2)
				L=C1+1;
			else
				R=C2-1;
			d[aa]=min(d[aa],min(CC1,CC2));
		}
	}
	return d[aa];
}
long long min_total_length(std::vector<int> r, std::vector<int> b) 
{
	n=r.size()+b.size();
	for(i=0;i<r.size();i++)
		a[++te]=mp(r[i],0);
	for(i=0;i<b.size();i++)
		a[++te]=mp(b[i],1);
	if(r[r.size()-1]<b[0])
		return com(1,n);
	sort(a+1,a+1+te);
	memset(d,-1,sizeof(d));
	return depe(1);
}

Compilation message

wiring.cpp: In function 'll com(ll, ll)':
wiring.cpp:24:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ii=0;ii<x.size();ii++)
            ~~^~~~~~~~~
wiring.cpp:26:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ii=x.size();ii<y.size();ii++)
                   ~~^~~~~~~~~
wiring.cpp:31:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ii=0;ii<y.size();ii++)
            ~~^~~~~~~~~
wiring.cpp:33:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ii=y.size();ii<x.size();ii++)
                   ~~^~~~~~~~~
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:79:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<r.size();i++)
          ~^~~~~~~~~
wiring.cpp:81:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<b.size();i++)
          ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1920 KB 3rd lines differ - on the 1st token, expected: '25859', found: '1000000000000000000'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 26 ms 5648 KB Output is correct
4 Correct 27 ms 5508 KB Output is correct
5 Correct 27 ms 5488 KB Output is correct
6 Correct 35 ms 7404 KB Output is correct
7 Correct 37 ms 7404 KB Output is correct
8 Correct 37 ms 7376 KB Output is correct
9 Correct 35 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 3 ms 1920 KB 3rd lines differ - on the 1st token, expected: '17703', found: '1000000000000000000'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Execution timed out 1058 ms 8548 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1920 KB 3rd lines differ - on the 1st token, expected: '25859', found: '1000000000000000000'
2 Halted 0 ms 0 KB -