Submission #114769

# Submission time Handle Problem Language Result Execution time Memory
114769 2019-06-02T15:58:37 Z faustaadp Wiring (IOI17_wiring) C++17
0 / 100
1000 ms 10864 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;
		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)
				d[aa]=min(d[aa],com(aa,ii)+depe(ii+1));
		}
	}
	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);
	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:62:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<r.size();i++)
          ~^~~~~~~~~
wiring.cpp:64:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<b.size();i++)
          ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Incorrect 3 ms 1920 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 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Execution timed out 1067 ms 8984 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Correct 4 ms 1920 KB Output is correct
3 Incorrect 208 ms 10864 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 3 ms 1920 KB Output is correct
2 Execution timed out 1061 ms 8160 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1920 KB Output is correct
2 Incorrect 3 ms 1920 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -