Submission #1079656

#TimeUsernameProblemLanguageResultExecution timeMemory
1079656c2zi6Longest Trip (IOI23_longesttrip)C++17
100 / 100
19 ms700 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 "longesttrip.h" int n; VI rev(VI a) { reverse(all(a)); return a; } // int are_connected(VI a, VI b); VI longest_trip(int N, int D) { n = N; VI path1; VI path2; VI order; rep(i, n) order.pb(i); mt19937 rng(chrono::steady_clock().now().time_since_epoch().count()); shuffle(all(order), rng); path1.pb(order[0]); path2.pb(order[1]); bool ardyoq = false; // ardyoq es gitem or P-n u Q-n kpac chen? replr(i, 2, n-1) { int R = order[i]; int P = path1.back(); int Q = path2.back(); if (ardyoq) { if (are_connected({P}, {R})) { path1.pb(R); ardyoq = false; } else path2.pb(R); } else { if (are_connected({P}, {R})) path1.pb(R); else if (are_connected({Q}, {R})) { path2.pb(R); ardyoq = true; } else { for (int x : rev(path2)) path1.pb(x); path2 = VI{R}; } } } if (are_connected({path2[0]}, {path1[0]})) { VI ans; for (int x : rev(path2)) ans.pb(x); for (int x : path1) ans.pb(x); return ans; } if (are_connected({path2.back()}, {path1[0]})) { VI ans; for (int x : path2) ans.pb(x); for (int x : path1) ans.pb(x); return ans; } if (are_connected({path1.back()}, {path2[0]})) { VI ans; for (int x : path1) ans.pb(x); for (int x : path2) ans.pb(x); return ans; } auto getind2 = [&](int ind1){ auto ardyoq = [&](int x) { VI tmp; rep(i, x+1) tmp.pb(path2[i]); return are_connected({path1[ind1]}, tmp); }; int l = -1, r = path2.size()-1; while (l + 1 < r) { int m = (l + r) / 2; if (ardyoq(m)) r = m; else l = m; } return r; }; auto getind1 = [&]() { auto ardyoq = [&](int x) { VI a, b; rep(i, x+1) a.pb(path1[i]); rep(i, path2.size()) b.pb(path2[i]); return are_connected(a, b); }; int l = -1, r = path1.size(); while (l + 1 < r) { int m = (l + r) / 2; if (ardyoq(m)) r = m; else l = m; } if (r == path1.size()) return -1; return r; }; int ind1 = getind1(); if (ind1 == -1) { if (path1.size() > path2.size()) return path1; return path2; } int ind2 = getind2(ind1); VI ans; replr(i, ind2+1, ind2+1 + path2.size()-1) { ans.pb(path2[i%(int)path2.size()]); } replr(i, ind1, ind1 + path1.size()-1) { ans.pb(path1[i%(int)path1.size()]); } return ans; }

Compilation message (stderr)

longesttrip.cpp: In lambda function:
longesttrip.cpp:124:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |         if (r == path1.size()) return -1;
      |             ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...