This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "railroad.h"
using namespace std;
long long plan_roller_coaster(vector<int> s, vector<int> t) {
int n = s.size();
multiset <pair <int, int> > ms;
map <pair <int, int>, int> mp;
pair <int, int> bad = {-1, -1};
for (int i = 0; i < n; i++) {
ms.insert({s[i], t[i]});
mp[{s[i], t[i]}]++;
}
for (int i = 0; i < n; i++){
auto it = ms.lower_bound({t[i], -1});
if (it == ms.end()){
bad = {s[i], t[i]};
}
else {
if (*it == make_pair(s[i], t[i]) && mp[{s[i], t[i]}] == 1) it++;
if (it == ms.end()) {
bad = {s[i], t[i]};
}
}
}
int last = 1;
for (int i = 0; i < n; i++){
auto it = ms.lower_bound({last, 0});
// cout << i << " " << last << " " << it->first << " " << it->second << "\n";
if (it != ms.end() && *it == bad && i != n-1) it++;
if (it == ms.end()) return 1;
last = it->second;
ms.erase(it);
}
if (bad.first != -1) return 1;
return 0;
}
# | 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... |