Submission #807488

# Submission time Handle Problem Language Result Execution time Memory
807488 2023-08-04T18:08:05 Z happypotato Roller Coaster Railroad (IOI16_railroad) C++17
34 / 100
126 ms 38476 KB
#include "railroad.h"

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second

vector<int> s, t;
int n;

int BruteDP() {
	int dp[(1 << n)][n];
	for (int conf = 0; conf < (1 << n); conf++) {
		for (int i = 0; i < n; i++) {
			dp[conf][i] = (conf == (1 << i) ? 0 : 1e18); 
		}
	}
	for (int bit = 2; bit <= n; bit++) {
		for (int conf = 0; conf < (1 << n); conf++) {
			if (__builtin_popcountll(conf) != bit) continue;
			for (int i = 0; i < n; i++) {
				if (conf & (1 << i)) {
					for (int j = 0; j < n; j++) {
						if (!bool(conf & (1 << j)) || i == j) continue;
						dp[conf][i] = min(dp[conf][i], dp[conf ^ (1 << i)][j] + max(0LL, t[j] - s[i]));
					}
				}
			}
		}
	}
	int ans = 1e18;
	for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]);
	return ans;
}



long long plan_roller_coaster(vector<int32_t> S, vector<int32_t> T) {
	n = S.size(); s.resize(n); t.resize(n);
	for (int i = 0; i < n; i++) {
		s[i] = S[i]; t[i] = T[i];
	}
	// for (int i = 0; i < n; i++) cerr << s[i] << ' '; cerr << endl;
	// for (int i = 0; i < n; i++) cerr << t[i] << ' '; cerr << endl;

	if (n <= 16) return BruteDP();

	vector<pii> v(n);
	for (int i = 0; i < n; i++) {
		v[i] = {s[i], t[i]};
	}
	sort(v.begin(), v.end(), greater<pii>());
	set<int> s;
	for (int i = 0; i < n; i++) s.insert(i);
	bool ans = 1;
	for (int st = n - 1; st >= n - 2; st--) {
		ans = 0;
		int cur = st;
		for (int turns = 0; turns < n; turns++) {
			s.erase(s.find(cur));
			if (turns == n - 1) break;
			int tar = v[cur].ss;
			int lb = 0, rb = n - 1;
			while (lb < rb) {
				int mid = (lb + rb + 1) >> 1;
				if (v[mid].ff >= tar) lb = mid;
				else rb = mid - 1;
			}
			int pos = lb;
			set<int>::iterator it = s.upper_bound(pos);
			if (it == s.begin()) {
				ans = 1;
				break;
			}
			cur = *(--it);
		}
		if (!ans) return 0;
	}
	return 1;
}

#undef int
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 2
2 Correct 0 ms 212 KB n = 2
3 Correct 0 ms 212 KB n = 2
4 Correct 0 ms 212 KB n = 2
5 Correct 0 ms 212 KB n = 2
6 Correct 0 ms 212 KB n = 2
7 Correct 1 ms 212 KB n = 3
8 Correct 1 ms 212 KB n = 3
9 Correct 0 ms 300 KB n = 3
10 Correct 0 ms 300 KB n = 8
11 Correct 0 ms 296 KB n = 8
12 Correct 1 ms 212 KB n = 8
13 Correct 1 ms 212 KB n = 8
14 Correct 1 ms 212 KB n = 8
15 Correct 1 ms 212 KB n = 8
16 Correct 1 ms 300 KB n = 8
17 Correct 1 ms 296 KB n = 8
18 Correct 1 ms 212 KB n = 8
19 Correct 1 ms 300 KB n = 3
20 Correct 1 ms 212 KB n = 7
21 Correct 1 ms 212 KB n = 8
22 Correct 1 ms 212 KB n = 8
23 Correct 1 ms 304 KB n = 8
24 Correct 1 ms 212 KB n = 8
25 Correct 1 ms 340 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 2
2 Correct 0 ms 212 KB n = 2
3 Correct 0 ms 212 KB n = 2
4 Correct 0 ms 212 KB n = 2
5 Correct 0 ms 212 KB n = 2
6 Correct 0 ms 212 KB n = 2
7 Correct 1 ms 212 KB n = 3
8 Correct 1 ms 212 KB n = 3
9 Correct 0 ms 300 KB n = 3
10 Correct 0 ms 300 KB n = 8
11 Correct 0 ms 296 KB n = 8
12 Correct 1 ms 212 KB n = 8
13 Correct 1 ms 212 KB n = 8
14 Correct 1 ms 212 KB n = 8
15 Correct 1 ms 212 KB n = 8
16 Correct 1 ms 300 KB n = 8
17 Correct 1 ms 296 KB n = 8
18 Correct 1 ms 212 KB n = 8
19 Correct 1 ms 300 KB n = 3
20 Correct 1 ms 212 KB n = 7
21 Correct 1 ms 212 KB n = 8
22 Correct 1 ms 212 KB n = 8
23 Correct 1 ms 304 KB n = 8
24 Correct 1 ms 212 KB n = 8
25 Correct 1 ms 340 KB n = 8
26 Correct 0 ms 212 KB n = 8
27 Correct 1 ms 212 KB n = 8
28 Correct 1 ms 212 KB n = 8
29 Correct 38 ms 8492 KB n = 16
30 Correct 37 ms 8404 KB n = 16
31 Correct 37 ms 8404 KB n = 16
32 Correct 37 ms 8404 KB n = 16
33 Correct 37 ms 8404 KB n = 16
34 Correct 37 ms 8404 KB n = 16
35 Correct 36 ms 8484 KB n = 16
36 Correct 17 ms 4052 KB n = 15
37 Correct 0 ms 212 KB n = 8
38 Correct 37 ms 8404 KB n = 16
39 Correct 36 ms 8404 KB n = 16
40 Correct 1 ms 340 KB n = 9
41 Correct 36 ms 8504 KB n = 16
42 Correct 41 ms 8532 KB n = 16
43 Correct 37 ms 8488 KB n = 16
44 Correct 1 ms 212 KB n = 9
45 Correct 17 ms 4052 KB n = 15
46 Correct 37 ms 8404 KB n = 16
47 Correct 37 ms 8488 KB n = 16
48 Correct 37 ms 8404 KB n = 16
# Verdict Execution time Memory Grader output
1 Correct 126 ms 19084 KB n = 199999
2 Runtime error 120 ms 38476 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 2
2 Correct 0 ms 212 KB n = 2
3 Correct 0 ms 212 KB n = 2
4 Correct 0 ms 212 KB n = 2
5 Correct 0 ms 212 KB n = 2
6 Correct 0 ms 212 KB n = 2
7 Correct 1 ms 212 KB n = 3
8 Correct 1 ms 212 KB n = 3
9 Correct 0 ms 300 KB n = 3
10 Correct 0 ms 300 KB n = 8
11 Correct 0 ms 296 KB n = 8
12 Correct 1 ms 212 KB n = 8
13 Correct 1 ms 212 KB n = 8
14 Correct 1 ms 212 KB n = 8
15 Correct 1 ms 212 KB n = 8
16 Correct 1 ms 300 KB n = 8
17 Correct 1 ms 296 KB n = 8
18 Correct 1 ms 212 KB n = 8
19 Correct 1 ms 300 KB n = 3
20 Correct 1 ms 212 KB n = 7
21 Correct 1 ms 212 KB n = 8
22 Correct 1 ms 212 KB n = 8
23 Correct 1 ms 304 KB n = 8
24 Correct 1 ms 212 KB n = 8
25 Correct 1 ms 340 KB n = 8
26 Correct 0 ms 212 KB n = 8
27 Correct 1 ms 212 KB n = 8
28 Correct 1 ms 212 KB n = 8
29 Correct 38 ms 8492 KB n = 16
30 Correct 37 ms 8404 KB n = 16
31 Correct 37 ms 8404 KB n = 16
32 Correct 37 ms 8404 KB n = 16
33 Correct 37 ms 8404 KB n = 16
34 Correct 37 ms 8404 KB n = 16
35 Correct 36 ms 8484 KB n = 16
36 Correct 17 ms 4052 KB n = 15
37 Correct 0 ms 212 KB n = 8
38 Correct 37 ms 8404 KB n = 16
39 Correct 36 ms 8404 KB n = 16
40 Correct 1 ms 340 KB n = 9
41 Correct 36 ms 8504 KB n = 16
42 Correct 41 ms 8532 KB n = 16
43 Correct 37 ms 8488 KB n = 16
44 Correct 1 ms 212 KB n = 9
45 Correct 17 ms 4052 KB n = 15
46 Correct 37 ms 8404 KB n = 16
47 Correct 37 ms 8488 KB n = 16
48 Correct 37 ms 8404 KB n = 16
49 Correct 126 ms 19084 KB n = 199999
50 Runtime error 120 ms 38476 KB Execution killed with signal 6
51 Halted 0 ms 0 KB -