Submission #927653

#TimeUsernameProblemLanguageResultExecution timeMemory
927653aykhnLongest Trip (IOI23_longesttrip)C++17
15 / 100
22 ms1256 KiB
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; vector<int> longest_trip(int n, int D) { vector<int> used(n, 0); vector<int> v1, v2, cur; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { if (are_connected({i}, {j})) { v1.push_back(i), v1.push_back(j); used[i] = used[j] = 1; break; } } if (!v1.empty()) break; } for (int i = 0; i < n; i++) { if (used[i]) continue; if (!v1.empty() && !v2.empty() && are_connected(v1, {i}) && are_connected(v2, {i})) { cur.clear(); for (int x : v1) cur.push_back(x); cur.push_back(i); for (int x : v2) cur.push_back(x); v1 = cur; } else if (are_connected(v1, {i})) { vector<int> nw; int idx = -1; for (int j = 0; j < v1.size(); j++) { if (are_connected({i}, {v1[j]})) { idx = j; break; } } nw.push_back(i), nw.push_back(v1[idx]); for (int j = (idx + 1) % v1.size(); j != idx; j = (j + 1) % v1.size()) { nw.push_back(v1[j]); } v1 = nw; } else { if (v2.empty()) v2.push_back(i); else { vector<int> nw; int idx = -1; for (int j = 0; j < v2.size(); j++) { if (are_connected({i}, {v2[j]})) { idx = j; break; } } nw.push_back(i), nw.push_back(v2[idx]); for (int j = (idx + 1) % v2.size(); j != idx; j = (j + 1) % v2.size()) { nw.push_back(v2[j]); } v2 = nw; } } // cout << i << ":\n"; // for (int x : v1) cout << x << ' '; // cout << '\n'; // for (int x : v2) cout << x << ' '; // cout << '\n'; // for (int x : cur) cout << x << ' '; // cout << '\n'; } if (max({v1.size(), v2.size(), cur.size()}) == v1.size()) return v1; if (max({v1.size(), v2.size(), cur.size()}) == v2.size()) return v2; return cur; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for (int j = 0; j < v1.size(); j++)
      |                             ~~^~~~~~~~~~~
longesttrip.cpp:60:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for (int j = 0; j < v2.size(); j++)
      |                                 ~~^~~~~~~~~~~
#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...