# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1208826 | kilikuma | Roller Coaster Railroad (IOI16_railroad) | C++20 | 577 ms | 34808 KiB |
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
vector<long long> coords; map<long long, long long> mp;
for (int i = 0; i < n; i ++) {
coords.push_back(s[i]);
coords.push_back(t[i]);
}
sort(coords.begin(), coords.end());
auto it = unique(coords.begin(), coords.end());
coords.resize(distance(coords.begin(), it));
for (int i = 0; i < coords.size(); i ++)
mp[coords[i]] = i;
for (int i = 0; i < n; i ++) {
s[i] = mp[s[i]];
t[i] = mp[t[i]];
}
vector<long long> cnt(2 * n + 1, 0);
for (int i = 0; i < n; i ++) {
if (s[i] == t[i]) continue;
if (s[i] < t[i]) {
cnt[s[i]] ++;
cnt[t[i]] --;
}
else {
cnt[t[i]] --;
cnt[s[i]] ++;
}
}
for (int i = 1; i <= 2 * n; i ++)
cnt[i] += cnt[i - 1];
for (int i = 0; i <= 2 * n; i ++)
if (cnt[i] > 1)
return 42;
for (int i = 0; i < n; i ++) {
if (s[i] == t[i]) {
if (cnt[s[i]] == 1)
return 42;
}
}
cout << n << " ";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |