Submission #1037352

#TimeUsernameProblemLanguageResultExecution timeMemory
1037352c2zi6Rail (IOI14_rail)C++14
100 / 100
44 ms912 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "rail.h" void findLocation(int n, int LOCATION0, int l[], int stype[]) { int A, B; A = 0; l[A] = LOCATION0; stype[A] = 1; if (n == 1) return; VI order; VI dist0(n); if (true) { VPI tmp; replr(i, 1, n-1) tmp.pb({dist0[i] = getDistance(0, i), i}); sort(all(tmp)); reverse(all(tmp)); B = tmp.back().ss; l[B] = l[A] + tmp.back().ff; stype[B] = 2; tmp.pop_back(); reverse(all(tmp)); for (auto[d, ind] : tmp) order.pb(ind); } set<int> C, D; C.insert(l[A]); D.insert(l[B]); for (int X : order) { /*cout << "PROCESSING " << X << endl;*/ /*cout << "A, B: " << A << ", " << B << endl;*/ int AX = getDistance(A, X); int BX = getDistance(B, X); l[X] = l[B] - BX; stype[X] = 1; if (l[X] != l[A]) { int p = *D.upper_bound(max(l[A], l[X])); if (AX == (p-l[X]) + (p-l[A])) goto end; } l[X] = l[A] + AX; stype[X] = 2; if (l[X] != l[B]) { int p = *prev(C.lower_bound(min(l[B], l[X]))); if (BX == (l[X]-p) + (l[B]-p)) goto end; } /*cout << "VAX QU" << endl;*/ if (l[A] + AX <= l[B]) { l[X] = l[B] - BX; stype[X] = 1; goto end; } if (l[B] - BX >= l[A]) { l[X] = l[A] + AX; stype[X] = 2; goto end; } /*cout << "VAX QUUUUUUUUU" << endl;*/ /*cout << AX << " = (" << l[0] << " - " << l[A] << ") + " << dist0[X] << endl;*/ if (AX == (l[0]-l[A]) + dist0[X]) { l[X] = l[A] + AX; stype[X] = 2; } else { l[X] = l[B] - BX; stype[X] = 1; } end: if (stype[X] == 1) { C.insert(l[X]); if (l[X] < l[A]) A = X; } else { D.insert(l[X]); if (l[X] > l[B]) B = X; } /*cout << "TYPE: " << stype[X] << endl;*/ /*cout << "LOCATION: " << l[X] << endl;*/ /*cout << endl;*/ } }

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:52:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |         for (auto[d, ind] : tmp) order.pb(ind);
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...