Submission #847604

#TimeUsernameProblemLanguageResultExecution timeMemory
847604dlalswp25Longest Trip (IOI23_longesttrip)C++17
100 / 100
11 ms856 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; bool ask(vector<int> a, vector<int> b) { if (!a.size() || !b.size()) return false; return are_connected(a, b); } bool adj(int a, int b) { return ask({a}, {b}); } std::vector<int> longest_trip(int N, int D) { vector<int> A = {0}, B; for (int i = 1; i < N; i++) { if (!B.size()) { (adj(A.back(), i) ? A : B).push_back(i); } else if (!adj(A.back(), i)) { B.push_back(i); } else if (i < N - 1) { int j = i++; if (adj(B.back(), i)) { A.push_back(j); B.push_back(i); if (adj(j, i)) { while (B.size()) { A.push_back(B.back()); B.pop_back(); } } } else { if (adj(j, i)) { A.push_back(j); A.push_back(i); } else { A.push_back(i); B.push_back(j); } } } else { A.push_back(i); if (adj(B.back(), i)) { while (B.size()) { A.push_back(B.back()); B.pop_back(); } } } } if (!B.size()) return A; if (!ask(A, B)) return (A.size() > B.size() ? A : B); if (adj(A.back(), B[0])) { A.insert(A.end(), B.begin(), B.end()); return A; } if (adj(A[0], B[0])) { reverse(A.begin(), A.end()); A.insert(A.end(), B.begin(), B.end()); return A; } vector<int> X = A; while (X.size() > 1) { vector<int> L, R; for (int i = 0; i < X.size(); i++) { if (i < X.size() / 2) L.push_back(X[i]); else R.push_back(X[i]); } if (ask(L, B)) X = L; else X = R; } int a = X[0]; X = B; while (X.size() > 1) { vector<int> L, R; for (int i = 0; i < X.size(); i++) { if (i < X.size() / 2) L.push_back(X[i]); else R.push_back(X[i]); } if (ask({a}, L)) X = L; else X = R; } int b = X[0]; vector<int> ans; int i; for (i = 0; i < A.size(); i++) { if (A[i] == a) break; } for (int j = (i + 1) % A.size(); j != i; j = (j + 1) % A.size()) { ans.push_back(A[j]); } ans.push_back(a); ans.push_back(b); for (i = 0; i < B.size(); i++) { if (B[i] == b) break; } for (int j = (i + 1) % B.size(); j != i; j = (j + 1) % B.size()) { ans.push_back(B[j]); } return ans; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for (int i = 0; i < X.size(); i++) {
      |                         ~~^~~~~~~~~~
longesttrip.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             if (i < X.size() / 2) L.push_back(X[i]);
      |                 ~~^~~~~~~~~~~~~~
longesttrip.cpp:78:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for (int i = 0; i < X.size(); i++) {
      |                         ~~^~~~~~~~~~
longesttrip.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             if (i < X.size() / 2) L.push_back(X[i]);
      |                 ~~^~~~~~~~~~~~~~
longesttrip.cpp:88:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for (i = 0; i < A.size(); i++) {
      |                 ~~^~~~~~~~~~
longesttrip.cpp:96:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for (i = 0; i < B.size(); i++) {
      |                 ~~^~~~~~~~~~
#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...