Submission #1021359

#TimeUsernameProblemLanguageResultExecution timeMemory
1021359vjudge1Roller Coaster Railroad (IOI16_railroad)C++17
0 / 100
114 ms10876 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; #define rall(s) s.rbegin(), s.rend() #define all(s) s.begin(), s.end() #define sz(s) (int)s.size() #define s second #define f first using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int N = 1e6, inf = 1e9 + 5; int pr[N], sz[N]; int get(int x) { if (pr[x] == x) return x; return pr[x] = get(pr[x]); } void unite(int a, int b) { a = get(a); b = get(b); if (a == b) return; if (sz[a] > sz[b]) swap(a, b); pr[a] = b, sz[b] += sz[a]; } ll plan_roller_coaster(vector<int> s, vector<int> t) { vector<int> x; t.push_back(1); s.push_back(inf); for (int v: s) x.push_back(v); for (int v: t) x.push_back(v); sort(all(x)); x.erase(unique(all(x)), x.end()); int n = sz(s), m = sz(x); vector<int> cnt(m); for (int i = 0; i < m; i++) pr[i] = i, sz[i] = 1; for (int i = 0; i < n; i++) { s[i] = lower_bound(all(x), s[i]) - x.begin(); t[i] = lower_bound(all(x), t[i]) - x.begin(); unite(s[i], t[i]); if (s[i] <= t[i]) cnt[s[i]]++, cnt[t[i]]--; else cnt[s[i]]--, cnt[t[i]]++; } for (int i = 0; i < m; i++) { if (i) cnt[i] += cnt[i - 1]; if (cnt[i] < 0) unite(i, i + 1); else if (cnt[i] > 0) return 1; } for (int i = 1; i < m; i++) { if (get(i) != get(i - 1)) return 1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...