Submission #1038349

#TimeUsernameProblemLanguageResultExecution timeMemory
1038349AndreyLongest Trip (IOI23_longesttrip)C++17
100 / 100
13 ms600 KiB
#include "longesttrip.h" #include<bits/stdc++.h> using namespace std; int n; int dude(vector<int>& wow, vector<int>& wut, int y) { vector<int> a(0); vector<int> b(0); if(y == -1) { for(int i = 0; i < wut.size(); i++) { b.push_back(wut[i]); } } else { b.push_back(wut[y]); } int l = 0,r = wow.size()-1; while(l < r) { int m = (l+r)/2; a.clear(); for(int i = l; i <= m; i++) { a.push_back(wow[i]); } if(are_connected(a,b)) { r = m; } else { l = m+1; } } return l; } std::vector<int> longest_trip(int N, int D) { n = N; vector<int> wow(0); vector<int> wut(0); wow.push_back(0); wut.push_back(1); for(int i = 2; i < n; i+=2) { bool a = are_connected({i},{wow[wow.size()-1]}); if(a) { wow.push_back(i); i--; continue; } bool b = are_connected({i},{wut[wut.size()-1]}); if(i == n-1) { if(b) { wut.push_back(i); } else { for(int j = wut.size()-1; j >= 0; j--) { wow.push_back(wut[j]); } wut.clear(); wut.push_back(i); } } else { bool c = are_connected({i},{i+1}); if(b&c) { wut.push_back(i); wut.push_back(i+1); } else if((!b)&c) { for(int j = wut.size()-1; j >= 0; j--) { wow.push_back(wut[j]); } wut.clear(); wut.push_back(i); wut.push_back(i+1); } else if(b&(!c)) { wut.push_back(i); wow.push_back(i+1); } else { wow.push_back(i+1); for(int j = wut.size()-1; j >= 0; j--) { wow.push_back(wut[j]); } wut.clear(); wut.push_back(i); } } } vector<int> ans(0); if(are_connected({wow[0]},{wut[0]})) { for(int i = wow.size()-1; i >= 0; i--) { ans.push_back(wow[i]); } for(int i = 0; i < wut.size(); i++) { ans.push_back(wut[i]); } return ans; } if(are_connected({wow[wow.size()-1]},{wut[0]})) { for(int i = 0; i < wow.size(); i++) { ans.push_back(wow[i]); } for(int i = 0; i < wut.size(); i++) { ans.push_back(wut[i]); } return ans; } if(are_connected({wow[0]},{wut[wut.size()-1]})) { for(int i = wow.size()-1; i >= 0; i--) { ans.push_back(wow[i]); } for(int i = wut.size()-1; i >= 0; i--) { ans.push_back(wut[i]); } return ans; } vector<int> a(0); vector<int> b(0); for(int i = 0; i < wow.size(); i++) { a.push_back(wow[i]); } for(int i = 0; i < wut.size(); i++) { b.push_back(wut[i]); } if(!are_connected(a,b)) { if(a.size() > b.size()) { return a; } else { return b; } } int x1 = dude(wow,wut,-1); int x2 = dude(wut,wow,x1); for(int i = x1+1; i < wow.size(); i++) { ans.push_back(wow[i]); } for(int i = 0; i <= x1; i++) { ans.push_back(wow[i]); } for(int i = x2; i < wut.size(); i++) { ans.push_back(wut[i]); } for(int i = 0; i < x2; i++) { ans.push_back(wut[i]); } return ans; }

Compilation message (stderr)

longesttrip.cpp: In function 'int dude(std::vector<int>&, std::vector<int>&, int)':
longesttrip.cpp:11:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         for(int i = 0; i < wut.size(); i++) {
      |                        ~~^~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:95:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for(int i = 0; i < wut.size(); i++) {
      |                        ~~^~~~~~~~~~~~
longesttrip.cpp:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int i = 0; i < wow.size(); i++) {
      |                        ~~^~~~~~~~~~~~
longesttrip.cpp:104:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for(int i = 0; i < wut.size(); i++) {
      |                        ~~^~~~~~~~~~~~
longesttrip.cpp:120:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |     for(int i = 0; i < wow.size(); i++) {
      |                    ~~^~~~~~~~~~~~
longesttrip.cpp:123:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |     for(int i = 0; i < wut.size(); i++) {
      |                    ~~^~~~~~~~~~~~
longesttrip.cpp:136:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for(int i = x1+1; i < wow.size(); i++) {
      |                       ~~^~~~~~~~~~~~
longesttrip.cpp:142:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |     for(int i = x2; i < wut.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...