Submission #1072409

#TimeUsernameProblemLanguageResultExecution timeMemory
1072409andrei_iorgulescuLongest Trip (IOI23_longesttrip)C++17
100 / 100
12 ms604 KiB
#include <bits/stdc++.h> #include "longesttrip.h" #warning That's not FB, that's my FB using namespace std; vector<int> longest_trip(int N, int D) { if (D == 3) { vector<int> ans; for (int i = 0; i < N; i++) ans.push_back(i); return ans; } if (D == 2) { deque<int> chn; if (are_connected({0}, {1})) { chn.push_back(0), chn.push_back(1); if (are_connected({chn.back()}, {2})) chn.push_back(2); else chn.push_front(2); } else { chn.push_back(1); chn.push_back(2); chn.push_back(0); } for (int i = 3; i < N; i++) { if (are_connected({i}, {chn.back()})) chn.push_back(i); else chn.push_front(i); } vector<int> ans; while (!chn.empty()) ans.push_back(chn.back()), chn.pop_back(); return ans; } vector<int> c1, c2; c1.push_back(0); for (int i = 1; i < N; i += 2) { if (i + 1 == N) { bool b1 = are_connected({i}, {c1.back()}); if (b1) c1.push_back(i); else { if (c2.empty()) c2.push_back(i); else { bool b2 = are_connected({i}, {c2.back()}); if (b2) c2.push_back(i); else { while (!c2.empty()) { c1.push_back(c2.back()); c2.pop_back(); } c2.push_back(i); } } } } else { bool bb = are_connected({i}, {i + 1}); if (bb) { bool b1 = are_connected({i}, {c1.back()}); if (b1) c1.push_back(i), c1.push_back(i + 1); else { if (c2.empty()) c2.push_back(i), c2.push_back(i + 1); else { bool b2 = are_connected({i}, {c2.back()}); if (b2) c2.push_back(i), c2.push_back(i + 1); else { while (!c2.empty()) { c1.push_back(c2.back()); c2.pop_back(); } c2.push_back(i), c2.push_back(i + 1); } } } } else { bool b1 = are_connected({i}, {c1.back()}); if (b1) { c1.push_back(i); if (c2.empty()) c2.push_back(i + 1); else { bool b2 = are_connected({i + 1}, {c2.back()}); if (b2) c2.push_back(i + 1); else { while (!c2.empty()) { c1.push_back(c2.back()); c2.pop_back(); } c2.push_back(i + 1); } } } else { c1.push_back(i + 1); if (c2.empty()) c2.push_back(i); else { bool b2 = are_connected({i}, {c2.back()}); if (b2) c2.push_back(i); else { while (!c2.empty()) { c1.push_back(c2.back()); c2.pop_back(); } c2.push_back(i); } } } } } } if (c2.empty()) return c1; if (!are_connected(c1, c2)) { if (c1.size() < c2.size()) swap(c1, c2); return c1; } vector<int> tq1, tq2; tq1.push_back(c1[0]); if (c1.size() > 1) tq1.push_back(c1.back()); tq2.push_back(c2[0]); if (c2.size() > 1) tq2.push_back(c2.back()); bool bb = are_connected(tq1, tq2); if (bb) { if (are_connected({c1[0]}, {c2[0]})) { reverse(c1.begin(), c1.end()); for (auto it : c2) c1.push_back(it); return c1; } if (are_connected({c1[0]}, {c2.back()})) { for (auto it : c1) c2.push_back(it); return c2; } if (are_connected({c1.back()}, {c2[0]})) { for (auto it : c2) c1.push_back(it); return c1; } reverse(c2.begin(), c2.end()); for (auto it : c2) c1.push_back(it); return c1; } else { int st = -1, pas = 1 << 7; while (pas != 0) { if (st + pas + 1 < c2.size()) { vector<int> qq; for (int i = 0; i <= st + pas; i++) qq.push_back(c2[i]); bool lmf = are_connected(c1, qq); if (!lmf) st += pas; } pas /= 2; } st++; int ps2 = st; int el2 = c2[st]; st = -1, pas = 1 << 7; while (pas != 0) { if (st + pas + 1 < c1.size()) { vector<int> qq; for (int i = 0; i <= st + pas; i++) qq.push_back(c1[i]); bool lmf = are_connected({el2}, qq); if (!lmf) st += pas; } pas /= 2; } st++; int ps1 = st; int el1 = c1[st]; vector<int> ans; for (int i = ps1 + 1; ; i++) { ans.push_back(c1[i % (int)c1.size()]); if (i % (int)c1.size() == ps1) break; } for (int i = ps2; ; i++) { ans.push_back(c2[i % (int)c2.size()]); if ((i + 1) % (int)c2.size() == ps2) break; } return ans; } }

Compilation message (stderr)

longesttrip.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
    3 | #warning That's not FB, that's my FB
      |  ^~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:199:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  199 |             if (st + pas + 1 < c2.size())
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~
longesttrip.cpp:216:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  216 |             if (st + pas + 1 < c1.size())
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~
longesttrip.cpp:229:13: warning: unused variable 'el1' [-Wunused-variable]
  229 |         int el1 = c1[st];
      |             ^~~
#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...