제출 #698088

#제출 시각아이디문제언어결과실행 시간메모리
698088qwerasdfzxclRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
182 ms12972 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; pair<int, int> a[200200]; int n, chk[200200]; long long plan_roller_coaster(std::vector<int> S, std::vector<int> T) { n = S.size(); priority_queue<pair<int, int>> pq1, pq2; for (int i=1;i<=n;i++){ a[i] = {S[i-1], T[i-1]}; pq1.emplace(a[i].first, i); pq2.emplace(a[i].second, i); chk[i] = 1; } int cnt = n; while(cnt > 1){ while(!pq1.empty() && !chk[pq1.top().second]) pq1.pop(); while(!pq2.empty() && !chk[pq2.top().second]) pq2.pop(); auto [e, i] = pq2.top(); pq2.pop(); auto [s, j] = pq1.top(); if (i==j){ auto p = pq1.top(); pq1.pop(); while(!pq1.empty() && !chk[pq1.top().second]) pq1.pop(); auto [ss, jj] = pq1.top(); pq1.pop(); s = ss, j = jj; pq1.push(p); } else pq1.pop(); if (s < e) return 1e18; a[i] = {a[i].first, a[j].second}; chk[j] = 0; pq1.emplace(a[i].first, i); pq2.emplace(a[i].second, i); cnt--; } 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...