Submission #296115

# Submission time Handle Problem Language Result Execution time Memory
296115 2020-09-10T09:42:19 Z RealSuperman1 Roller Coaster Railroad (IOI16_railroad) C++14
64 / 100
260 ms 20092 KB
#include "railroad.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pll pair<long long, long long>
#define pii pair<int, int>

using namespace std;

const ll INF = 1e18;

int n;

bool cmp(pii x, pii y) {
	return x.fi > y.fi;
}

ll case3(vector <int> s, vector <int> t) {
	vector <pii> t1(n);
	for (int i = 0; i < n; i++)
		t1[i] = {t[i], i};
	sort(t1.begin(), t1.end(), cmp);
//	for (auto to : s1)
//		cout << to.fi << " " << to.se << endl;
//	cout << endl;
//	return 0;
	set <pii> sn = {};
	for (int i = 0; i < n; i++)
		sn.insert({s[i], i});
	set <pii>::iterator it;
	for (int i = 0; i < n; i++) {
		it = sn.lower_bound({t1[i].fi, 0});
		if (it == sn.end())
			continue;
		pii val = *it;
		if (val.se == t1[i].se)
			it = sn.upper_bound(val);
		if (it == sn.end())
			continue;
		val = *it;
//		cout << t1[i].se << "->" << val.se << endl;
		sn.erase(it);
	}
	if (sn.size() <= 1)
		return 0;
	return 1;
}

ll plan_roller_coaster(vector <int> s, vector <int> t) {
	n = s.size();
	if (n > 16) {
		return case3(s, t);
	}
	vector < vector <ll> > w;
	vector < vector <ll> > dp;
	w.resize(n);
	for (int i = 0; i < n; i++) {
		w[i].resize(n);
		for (int j = 0; j < n; j++) {
			if (i == j)
				continue;
			w[i][j] = max(0, t[i] - s[j]); 
		}
	}
	dp.resize((1 << n));
	for (int mask = 0; mask < (1 << n); mask++) {
		dp[mask].resize(n);
		for (int i = 0; i < n; i++)
			dp[mask][i] = INF;
	}
	for (int i = 0; i < n; i++)
		dp[0][i] = 0;
	vector <int> b;
	for (int mask = 1; mask < (1 << n); mask++) {
		b.clear();
		for (int i = 0; i < n; i++)
			if (1 & (mask >> i))
				b.pb(i);
		if (b.size() == 1) {
			dp[mask][b[0]] = 0;
			continue;
		}
		for (int i = 0; i < b.size(); i++)
			for (int j = 0; j < b.size(); j++) {
				if (i == j)
					continue;
				int mask1 = (mask ^ (1 << b[i]));
				dp[mask][b[i]] = min(dp[mask][b[i]], dp[mask1][b[j]] + w[b[j]][b[i]]);
			}
	}
	ll ans = INF;
	for (int i = 0; i < n; i++)
		ans = min(ans, dp[(1 << n) - 1][i]);
	return ans;
}

Compilation message

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:85:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for (int i = 0; i < b.size(); i++)
      |                   ~~^~~~~~~~~~
railroad.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    for (int j = 0; j < b.size(); j++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB n = 2
2 Correct 0 ms 256 KB n = 2
3 Correct 1 ms 256 KB n = 2
4 Correct 1 ms 256 KB n = 2
5 Correct 1 ms 256 KB n = 2
6 Correct 0 ms 256 KB n = 2
7 Correct 1 ms 256 KB n = 3
8 Correct 1 ms 256 KB n = 3
9 Correct 0 ms 256 KB n = 3
10 Correct 1 ms 384 KB n = 8
11 Correct 1 ms 384 KB n = 8
12 Correct 1 ms 384 KB n = 8
13 Correct 1 ms 384 KB n = 8
14 Correct 1 ms 384 KB n = 8
15 Correct 1 ms 384 KB n = 8
16 Correct 1 ms 384 KB n = 8
17 Correct 1 ms 304 KB n = 8
18 Correct 1 ms 384 KB n = 8
19 Correct 1 ms 256 KB n = 3
20 Correct 1 ms 384 KB n = 7
21 Correct 1 ms 384 KB n = 8
22 Correct 1 ms 384 KB n = 8
23 Correct 1 ms 384 KB n = 8
24 Correct 0 ms 384 KB n = 8
25 Correct 1 ms 384 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB n = 2
2 Correct 0 ms 256 KB n = 2
3 Correct 1 ms 256 KB n = 2
4 Correct 1 ms 256 KB n = 2
5 Correct 1 ms 256 KB n = 2
6 Correct 0 ms 256 KB n = 2
7 Correct 1 ms 256 KB n = 3
8 Correct 1 ms 256 KB n = 3
9 Correct 0 ms 256 KB n = 3
10 Correct 1 ms 384 KB n = 8
11 Correct 1 ms 384 KB n = 8
12 Correct 1 ms 384 KB n = 8
13 Correct 1 ms 384 KB n = 8
14 Correct 1 ms 384 KB n = 8
15 Correct 1 ms 384 KB n = 8
16 Correct 1 ms 384 KB n = 8
17 Correct 1 ms 304 KB n = 8
18 Correct 1 ms 384 KB n = 8
19 Correct 1 ms 256 KB n = 3
20 Correct 1 ms 384 KB n = 7
21 Correct 1 ms 384 KB n = 8
22 Correct 1 ms 384 KB n = 8
23 Correct 1 ms 384 KB n = 8
24 Correct 0 ms 384 KB n = 8
25 Correct 1 ms 384 KB n = 8
26 Correct 1 ms 384 KB n = 8
27 Correct 0 ms 384 KB n = 8
28 Correct 0 ms 384 KB n = 8
29 Correct 40 ms 11136 KB n = 16
30 Correct 40 ms 11136 KB n = 16
31 Correct 40 ms 11168 KB n = 16
32 Correct 39 ms 11136 KB n = 16
33 Correct 40 ms 11136 KB n = 16
34 Correct 42 ms 11136 KB n = 16
35 Correct 40 ms 11136 KB n = 16
36 Correct 18 ms 5248 KB n = 15
37 Correct 1 ms 384 KB n = 8
38 Correct 40 ms 11136 KB n = 16
39 Correct 40 ms 11136 KB n = 16
40 Correct 1 ms 384 KB n = 9
41 Correct 39 ms 11136 KB n = 16
42 Correct 39 ms 11136 KB n = 16
43 Correct 39 ms 11136 KB n = 16
44 Correct 1 ms 384 KB n = 9
45 Correct 18 ms 5248 KB n = 15
46 Correct 40 ms 11136 KB n = 16
47 Correct 40 ms 11136 KB n = 16
48 Correct 41 ms 11136 KB n = 16
# Verdict Execution time Memory Grader output
1 Correct 243 ms 16504 KB n = 199999
2 Correct 238 ms 19832 KB n = 199991
3 Correct 245 ms 19832 KB n = 199993
4 Correct 166 ms 14840 KB n = 152076
5 Correct 89 ms 9464 KB n = 93249
6 Correct 232 ms 18808 KB n = 199910
7 Correct 230 ms 19192 KB n = 199999
8 Correct 219 ms 18808 KB n = 199997
9 Correct 198 ms 16888 KB n = 171294
10 Correct 157 ms 14072 KB n = 140872
11 Correct 226 ms 18808 KB n = 199886
12 Correct 235 ms 19192 KB n = 199996
13 Correct 234 ms 18808 KB n = 200000
14 Correct 223 ms 19064 KB n = 199998
15 Correct 239 ms 19096 KB n = 200000
16 Correct 235 ms 19448 KB n = 199998
17 Correct 236 ms 19832 KB n = 200000
18 Correct 260 ms 19068 KB n = 190000
19 Correct 201 ms 17692 KB n = 177777
20 Correct 100 ms 10104 KB n = 100000
21 Correct 246 ms 19832 KB n = 200000
22 Correct 238 ms 19832 KB n = 200000
23 Correct 254 ms 19992 KB n = 200000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB n = 2
2 Correct 0 ms 256 KB n = 2
3 Correct 1 ms 256 KB n = 2
4 Correct 1 ms 256 KB n = 2
5 Correct 1 ms 256 KB n = 2
6 Correct 0 ms 256 KB n = 2
7 Correct 1 ms 256 KB n = 3
8 Correct 1 ms 256 KB n = 3
9 Correct 0 ms 256 KB n = 3
10 Correct 1 ms 384 KB n = 8
11 Correct 1 ms 384 KB n = 8
12 Correct 1 ms 384 KB n = 8
13 Correct 1 ms 384 KB n = 8
14 Correct 1 ms 384 KB n = 8
15 Correct 1 ms 384 KB n = 8
16 Correct 1 ms 384 KB n = 8
17 Correct 1 ms 304 KB n = 8
18 Correct 1 ms 384 KB n = 8
19 Correct 1 ms 256 KB n = 3
20 Correct 1 ms 384 KB n = 7
21 Correct 1 ms 384 KB n = 8
22 Correct 1 ms 384 KB n = 8
23 Correct 1 ms 384 KB n = 8
24 Correct 0 ms 384 KB n = 8
25 Correct 1 ms 384 KB n = 8
26 Correct 1 ms 384 KB n = 8
27 Correct 0 ms 384 KB n = 8
28 Correct 0 ms 384 KB n = 8
29 Correct 40 ms 11136 KB n = 16
30 Correct 40 ms 11136 KB n = 16
31 Correct 40 ms 11168 KB n = 16
32 Correct 39 ms 11136 KB n = 16
33 Correct 40 ms 11136 KB n = 16
34 Correct 42 ms 11136 KB n = 16
35 Correct 40 ms 11136 KB n = 16
36 Correct 18 ms 5248 KB n = 15
37 Correct 1 ms 384 KB n = 8
38 Correct 40 ms 11136 KB n = 16
39 Correct 40 ms 11136 KB n = 16
40 Correct 1 ms 384 KB n = 9
41 Correct 39 ms 11136 KB n = 16
42 Correct 39 ms 11136 KB n = 16
43 Correct 39 ms 11136 KB n = 16
44 Correct 1 ms 384 KB n = 9
45 Correct 18 ms 5248 KB n = 15
46 Correct 40 ms 11136 KB n = 16
47 Correct 40 ms 11136 KB n = 16
48 Correct 41 ms 11136 KB n = 16
49 Correct 243 ms 16504 KB n = 199999
50 Correct 238 ms 19832 KB n = 199991
51 Correct 245 ms 19832 KB n = 199993
52 Correct 166 ms 14840 KB n = 152076
53 Correct 89 ms 9464 KB n = 93249
54 Correct 232 ms 18808 KB n = 199910
55 Correct 230 ms 19192 KB n = 199999
56 Correct 219 ms 18808 KB n = 199997
57 Correct 198 ms 16888 KB n = 171294
58 Correct 157 ms 14072 KB n = 140872
59 Correct 226 ms 18808 KB n = 199886
60 Correct 235 ms 19192 KB n = 199996
61 Correct 234 ms 18808 KB n = 200000
62 Correct 223 ms 19064 KB n = 199998
63 Correct 239 ms 19096 KB n = 200000
64 Correct 235 ms 19448 KB n = 199998
65 Correct 236 ms 19832 KB n = 200000
66 Correct 260 ms 19068 KB n = 190000
67 Correct 201 ms 17692 KB n = 177777
68 Correct 100 ms 10104 KB n = 100000
69 Correct 246 ms 19832 KB n = 200000
70 Correct 238 ms 19832 KB n = 200000
71 Correct 254 ms 19992 KB n = 200000
72 Correct 246 ms 20092 KB n = 200000
73 Incorrect 252 ms 19960 KB answer is not correct: 1 instead of 34382661743
74 Halted 0 ms 0 KB -