Submission #71211

#TimeUsernameProblemLanguageResultExecution timeMemory
71211evpipisRoller Coaster Railroad (IOI16_railroad)C++11
0 / 100
419 ms43564 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; //#define TEST #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; typedef pair<int, int> ii; const int inf = 1e9+5, len = 2e5+5; vector<pair<ii, int> > vec; set<int> mys; int pos[len]; bool comp(pair<ii, int> a, pair<ii, int> b){ if (a.fi.fi > b.fi.fi) return true; if (a.fi.fi < b.fi.fi) return false; return (a.fi.se < b.fi.se); } long long plan_roller_coaster(vector<int> s, vector<int> t) { int n = (int) s.size(), ans = 0; for (int i = 0; i < n; i++){ //printf("%d %d\n", s[i], t[i]); vec.pb(mp(mp(s[i], 0), i)); vec.pb(mp(mp(t[i], 1), i)); } vec.pb(mp(mp(inf, 0), n)); vec.pb(mp(mp(0, 1), n)); sort(vec.begin(), vec.end(), comp); for (int i = 0; i < vec.size(); i++) if (vec[i].fi.se) pos[vec[i].se] = i; for (int i = 0; i < vec.size(); i++){ //printf("(%d, %d)\n", vec[i].fi.se, pos[vec[i].se]); if (vec[i].fi.se == 0){ mys.insert(pos[vec[i].se]); } else{ set<int>::iterator it = mys.upper_bound(i); if (it != mys.end()) mys.erase(it); else if (!mys.empty() && *mys.begin() < i) mys.erase(mys.begin()); else ans = 1; } /*for (auto it: mys) printf("%d ", it); printf("\n"); printf("i = %d, ans = %d\n", i, ans);*/ } return ans; } #ifdef TEST int main() { freopen("01", "r", stdin); int n; assert(1 == scanf("%d", &n)); std::vector<int> s(n), t(n); for (int i = 0; i < n; ++i) assert(2 == scanf("%d%d", &s[i], &t[i])); long long ans = plan_roller_coaster(s, t); printf("%lld\n", ans); return 0; } #endif // TEST

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:37:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
railroad.cpp:41:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...