Submission #958831

# Submission time Handle Problem Language Result Execution time Memory
958831 2024-04-06T23:46:09 Z MinaRagy06 Roller Coaster Railroad (IOI16_railroad) C++17
0 / 100
2000 ms 17808 KB
#include <bits/stdc++.h>
#include "railroad.h"
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long

ll plan_roller_coaster(vector<int> in, vector<int> out) {
	int n = in.size();
	set<array<int, 2>> s;
	for (int i = 0; i < n; i++) {
		s.insert({in[i], out[i]});
	}
	vector<array<int, 2>> a;
	while (s.size()) {
		array<int, 2> val = *s.begin();
		s.erase(s.begin());
		int st = val[0];
		while (1) {
			auto it = s.lower_bound({val[1], 0});
			if (it == s.end()) {
				break;
			}
			val = *it;
			s.erase(it);
		}
		int en = val[1];
		a.push_back({st, en});
	}
	n = a.size();
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i][1] - a[i][0];
	}
	if (n == 1) {
		return 0;
	}
	ll ans = 1e18;
	for (int x = 0; x < n; x++) {
		for (int y = 0; y < n; y++) {
			if (x == y) continue;
			ans = min(ans, sum + a[x][0] - a[y][1]);
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 2
2 Correct 0 ms 348 KB n = 2
3 Correct 0 ms 348 KB n = 2
4 Correct 0 ms 348 KB n = 2
5 Correct 0 ms 348 KB n = 2
6 Correct 0 ms 348 KB n = 2
7 Correct 1 ms 348 KB n = 3
8 Incorrect 0 ms 348 KB answer is not correct: 209372231 instead of 102553483
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 2
2 Correct 0 ms 348 KB n = 2
3 Correct 0 ms 348 KB n = 2
4 Correct 0 ms 348 KB n = 2
5 Correct 0 ms 348 KB n = 2
6 Correct 0 ms 348 KB n = 2
7 Correct 1 ms 348 KB n = 3
8 Incorrect 0 ms 348 KB answer is not correct: 209372231 instead of 102553483
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 12856 KB n = 199999
2 Correct 150 ms 16724 KB n = 199991
3 Execution timed out 2036 ms 17808 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 2
2 Correct 0 ms 348 KB n = 2
3 Correct 0 ms 348 KB n = 2
4 Correct 0 ms 348 KB n = 2
5 Correct 0 ms 348 KB n = 2
6 Correct 0 ms 348 KB n = 2
7 Correct 1 ms 348 KB n = 3
8 Incorrect 0 ms 348 KB answer is not correct: 209372231 instead of 102553483
9 Halted 0 ms 0 KB -