Submission #851523

#TimeUsernameProblemLanguageResultExecution timeMemory
851523batmendbarLongest Trip (IOI23_longesttrip)C++17
0 / 100
1 ms344 KiB
#include "longesttrip.h" #include <algorithm> #include <random> #include <stack> #include <iostream> using namespace std; vector<int> longest_trip(int N, int D) { vector<int> big, small, nodes; for (int i = 0; i < N; i++) nodes.push_back(i); random_device rd; mt19937 g(rd()); shuffle(nodes.begin(), nodes.end(), g); for (int node : nodes) cout << node << ' '; cout << '\n'; cout.flush(); big.push_back(nodes[0]); small.push_back(nodes[1]); bool guarantee = false; for (int i = 2; i < N; i++) { if (are_connected(vector<int>{big.back()}, vector<int>{nodes[i]})) { big.push_back(nodes[i]); guarantee = false; } else if (guarantee) { small.push_back(nodes[i]); } else if (are_connected(vector<int>{small.back()}, vector<int>{nodes[i]})) { small.push_back(nodes[i]); guarantee = true; } else { if (small.size() == 1) guarantee = true; while (!small.empty()) { big.push_back(small.back()); small.pop_back(); } small.push_back(nodes[i]); } } // cout << "Big: "; // for (int i : big) cout << i << ' '; // cout << '\n'; // cout << "Small: "; // for (int i : small) cout << i << ' '; // cout << '\n'; // cout.flush(); // return nodes; if (are_connected(big, small)) { return nodes; if (are_connected(vector<int>{big.back()}, vector<int>{small.back()}) || are_connected(vector<int>{big[0]}, vector<int>{small[0]}) ) { big.insert(big.end(), small.rbegin(), small.rend()); return big; } if (are_connected(vector<int>{big.back()}, vector<int>{small[0]}) || are_connected(vector<int>{big[0]}, vector<int>{small.back()})) { big.insert(big.end(), small.begin(), small.end()); return big; } int l = 0, r = big.size() - 1; while (l < r) { int mid = (l + r) / 2; std::vector<int>::iterator begin = big.begin() + l; // Start from index 1 std::vector<int>::iterator end = big.begin() + mid + 1; vector<int> tempBig(begin, end); if (are_connected(small, tempBig)) { r = mid; } else { l = mid + 1; } } int bigInd = l; l = 0, r = small.size() - 1; while (l < r) { int mid = (l + r) / 2; std::vector<int>::iterator begin = small.begin() + l; // Start from index 1 std::vector<int>::iterator end = small.begin() + mid + 1; vector<int> tempSmall(begin, end); if (are_connected(tempSmall, vector<int>{big[bigInd]})) { r = mid; } else { l = mid + 1; } } int smallInd = l; vector<int> ans; for (int i = smallInd + 1; i < small.size(); i++) { ans.push_back(small[i]); } for (int i = 0; i <= smallInd; i++) { ans.push_back(small[i]); } for (int i = bigInd; i <= big.size(); i++) { ans.push_back(big[i]); } for (int i = 0; i < bigInd; i++) { ans.push_back(big[i]); } return ans; } else { if (big.size() < small.size()) return small; else return big; } }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:103:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for (int i = smallInd + 1; i < small.size(); i++) {
      |                                    ~~^~~~~~~~~~~~~~
longesttrip.cpp:109:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         for (int i = bigInd; i <= big.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...