Submission #114773

# Submission time Handle Problem Language Result Execution time Memory
114773 2019-06-02T16:07:11 Z faustaadp Wiring (IOI17_wiring) C++17
30 / 100
1000 ms 10276 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)+min(depe(ii+1),depe(ii)));
		}
	}
	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: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 3 ms 1916 KB Output is correct
2 Correct 3 ms 1920 KB Output is correct
3 Correct 3 ms 1920 KB Output is correct
4 Correct 3 ms 1920 KB Output is correct
5 Correct 3 ms 1920 KB Output is correct
6 Correct 3 ms 1920 KB Output is correct
7 Correct 19 ms 1920 KB Output is correct
8 Correct 19 ms 2048 KB Output is correct
9 Correct 11 ms 1920 KB Output is correct
10 Correct 22 ms 1920 KB Output is correct
11 Correct 7 ms 1920 KB Output is correct
12 Correct 20 ms 1920 KB Output is correct
13 Correct 13 ms 1920 KB Output is correct
14 Correct 7 ms 1924 KB Output is correct
15 Correct 12 ms 2048 KB Output is correct
16 Correct 16 ms 1972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 29 ms 5620 KB Output is correct
4 Correct 27 ms 5484 KB Output is correct
5 Correct 27 ms 5496 KB Output is correct
6 Correct 35 ms 7408 KB Output is correct
7 Correct 35 ms 7404 KB Output is correct
8 Correct 35 ms 7404 KB Output is correct
9 Correct 37 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 1920 KB Output is correct
3 Correct 198 ms 10188 KB Output is correct
4 Correct 378 ms 8696 KB Output is correct
5 Correct 3 ms 1920 KB Output is correct
6 Correct 3 ms 1920 KB Output is correct
7 Correct 3 ms 1920 KB Output is correct
8 Correct 3 ms 1920 KB Output is correct
9 Correct 3 ms 1920 KB Output is correct
10 Correct 3 ms 1920 KB Output is correct
11 Correct 3 ms 1920 KB Output is correct
12 Correct 3 ms 1936 KB Output is correct
13 Correct 3 ms 1920 KB Output is correct
14 Correct 3 ms 1920 KB Output is correct
15 Correct 3 ms 1920 KB Output is correct
16 Correct 3 ms 1920 KB Output is correct
17 Correct 3 ms 1920 KB Output is correct
18 Correct 193 ms 10232 KB Output is correct
19 Correct 202 ms 10276 KB Output is correct
20 Correct 346 ms 8824 KB Output is correct
21 Correct 193 ms 10232 KB Output is correct
22 Correct 224 ms 9860 KB Output is correct
23 Correct 228 ms 9720 KB Output is correct
24 Correct 225 ms 9764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1920 KB Output is correct
2 Execution timed out 1085 ms 6872 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1916 KB Output is correct
2 Correct 3 ms 1920 KB Output is correct
3 Correct 3 ms 1920 KB Output is correct
4 Correct 3 ms 1920 KB Output is correct
5 Correct 3 ms 1920 KB Output is correct
6 Correct 3 ms 1920 KB Output is correct
7 Correct 19 ms 1920 KB Output is correct
8 Correct 19 ms 2048 KB Output is correct
9 Correct 11 ms 1920 KB Output is correct
10 Correct 22 ms 1920 KB Output is correct
11 Correct 7 ms 1920 KB Output is correct
12 Correct 20 ms 1920 KB Output is correct
13 Correct 13 ms 1920 KB Output is correct
14 Correct 7 ms 1924 KB Output is correct
15 Correct 12 ms 2048 KB Output is correct
16 Correct 16 ms 1972 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 29 ms 5620 KB Output is correct
20 Correct 27 ms 5484 KB Output is correct
21 Correct 27 ms 5496 KB Output is correct
22 Correct 35 ms 7408 KB Output is correct
23 Correct 35 ms 7404 KB Output is correct
24 Correct 35 ms 7404 KB Output is correct
25 Correct 37 ms 7404 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 3 ms 1920 KB Output is correct
28 Correct 198 ms 10188 KB Output is correct
29 Correct 378 ms 8696 KB Output is correct
30 Correct 3 ms 1920 KB Output is correct
31 Correct 3 ms 1920 KB Output is correct
32 Correct 3 ms 1920 KB Output is correct
33 Correct 3 ms 1920 KB Output is correct
34 Correct 3 ms 1920 KB Output is correct
35 Correct 3 ms 1920 KB Output is correct
36 Correct 3 ms 1920 KB Output is correct
37 Correct 3 ms 1936 KB Output is correct
38 Correct 3 ms 1920 KB Output is correct
39 Correct 3 ms 1920 KB Output is correct
40 Correct 3 ms 1920 KB Output is correct
41 Correct 3 ms 1920 KB Output is correct
42 Correct 3 ms 1920 KB Output is correct
43 Correct 193 ms 10232 KB Output is correct
44 Correct 202 ms 10276 KB Output is correct
45 Correct 346 ms 8824 KB Output is correct
46 Correct 193 ms 10232 KB Output is correct
47 Correct 224 ms 9860 KB Output is correct
48 Correct 228 ms 9720 KB Output is correct
49 Correct 225 ms 9764 KB Output is correct
50 Correct 3 ms 1920 KB Output is correct
51 Execution timed out 1085 ms 6872 KB Time limit exceeded
52 Halted 0 ms 0 KB -