Submission #846120

#TimeUsernameProblemLanguageResultExecution timeMemory
846120math_rabbit_1028Longest Trip (IOI23_longesttrip)C++17
40 / 100
811 ms2016 KiB
#include <bits/stdc++.h> #include "longesttrip.h" using namespace std; int n; vector<int> adj[256]; vector<int> res; vector<int> longest_trip(int N, int D) { n = N; res.clear(); for (int i = 0; i < n; i++) adj[i].clear(); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (are_connected({i}, {j})) { adj[i].push_back(j); adj[j].push_back(i); } } } res.push_back(0); while (true) { int bef = res.size(); for (int i = 0; i < adj[res.back()].size(); i++) { int v = adj[res.back()][i]; bool f = false; for (int j = 0; j < res.size(); j++) { if (res[j] == v) f = true; } if (f) continue; res.push_back(v); break; } if (bef == res.size()) break; } reverse(res.begin(), res.end()); while (true) { int bef = res.size(); for (int i = 0; i < adj[res.back()].size(); i++) { int v = adj[res.back()][i]; bool f = false; for (int j = 0; j < res.size(); j++) { if (res[j] == v) f = true; } if (f) continue; res.push_back(v); break; } if (bef == res.size()) break; } if (res.size() >= n - res.size()) { return res; } vector<int> temp; for (int i = 0; i < n; i++) { bool f = false; for (int j = 0; j < res.size(); j++) { if (res[j] == i) f = true; } if (f) continue; temp.push_back(i); } return temp; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int i = 0; i < adj[res.back()].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~
longesttrip.cpp:28:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             for (int j = 0; j < res.size(); j++) {
      |                             ~~^~~~~~~~~~~~
longesttrip.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if (bef == res.size()) break;
      |             ~~~~^~~~~~~~~~~~~
longesttrip.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 0; i < adj[res.back()].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~
longesttrip.cpp:43:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for (int j = 0; j < res.size(); j++) {
      |                             ~~^~~~~~~~~~~~
longesttrip.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (bef == res.size()) break;
      |             ~~~~^~~~~~~~~~~~~
longesttrip.cpp:60:27: 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 < res.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...