Submission #1064039

#TimeUsernameProblemLanguageResultExecution timeMemory
1064039parsadox2Longest Trip (IOI23_longesttrip)C++17
85 / 100
15 ms680 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; const int N = 256; int n , d; bool in_path[N]; vector<int> longest_trip(int nn, int dd) { n = nn; d = dd; vector <int> p1; vector <int> p2; for(int i = 0 ; i < n ; i++) { if(p1.empty()) { p1.push_back(i); continue; } else if(p2.empty()) { p2.push_back(i); continue; } vector <int> A; A.push_back(p1.back()); vector <int> B; B.push_back(i); if(are_connected(A , B)) { p1.push_back(i); continue; } A.back() = p2.back(); if(are_connected(A , B)) { p2.push_back(i); continue; } reverse(p2.begin() , p2.end()); for(auto u : p2) p1.push_back(u); p2 = B; } if(p2.empty()) return p1; vector <int> A; A.push_back(p1.back()); vector <int> B; B.push_back(p2.back()); if(are_connected(A , B)) { reverse(p2.begin() , p2.end()); for(auto u : p2) p1.push_back(u); p2.clear(); } if(p2.empty()) return p1; A.back() = p1[0]; if(are_connected(A , B)) { reverse(p1.begin() , p1.end()); reverse(p2.begin() , p2.end()); for(auto u : p2) p1.push_back(u); p2.clear(); } if(p2.empty()) return p1; B.back() = p2[0]; if(are_connected(A , B)) { reverse(p1.begin() , p1.end()); for(auto u : p2) p1.push_back(u); p2.clear(); } if(p2.empty()) return p1; A.back() = p1.back(); if(are_connected(A , B)) { for(auto u : p2) p1.push_back(u); p2.clear(); } if(p2.empty()) return p1; if(!are_connected(p1 , p2)) { if(p1.size() > p2.size()) return p1; return p2; } int low = 0 , high = p1.size(); while(high - low > 1) { int mid = (low + high) >> 1; vector <int> tmp; for(int i = low ; i < mid ; i++) tmp.push_back(p1[i]); if(are_connected(tmp , p2)) high = mid; else low = mid; } vector <int> res; for(int i = low + 1 ; i < p1.size() ; i++) res.push_back(p1[i]); for(int i = 0 ; i <= low ; i++) res.push_back(p1[i]); A.back() = res.back(); low = 0; high = p2.size(); while(high - low > 1) { int mid = (low + high) >> 1; vector <int> tmp; for(int i = low ; i < mid ; i++) tmp.push_back(p2[i]); if(are_connected(A , tmp)) high = mid; else low = mid; } for(int i = low ; i < p2.size() ; i++) res.push_back(p2[i]); for(int i = 0 ; i < low ; i++) res.push_back(p2[i]); return res; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:108:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i = low + 1 ; i < p1.size() ; i++)
      |                           ~~^~~~~~~~~~~
longesttrip.cpp:125:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for(int i = low ; i < p2.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...