제출 #928439

#제출 시각아이디문제언어결과실행 시간메모리
928439n1k가장 긴 여행 (IOI23_longesttrip)C++17
85 / 100
11 ms948 KiB
#include "longesttrip.h" #include <bits/stdc++.h> using namespace std; /* OBSERVE: path meargen hinten und vorne dazu * - * * * - * */ std::vector<int> longest_trip(int N, int D){ // vorraussetzung path[0].end nicht mit path[1].end verbunden vector<int> path[2]; path[0].push_back(0); for(int i=1; i<N; i++){ if(are_connected({*path[0].rbegin()}, {i})){ path[0].push_back(i); if(path[1].size() and are_connected({path[0][path[0].size()-1]}, {path[1][path[1].size()-1]})){ reverse(path[1].begin(), path[1].end()); path[0].insert(path[0].end(), path[1].begin(), path[1].end()); path[1].clear(); } }else{ path[1].push_back(i); } } if(path[1].empty() or not are_connected(path[0], path[1])){ if(path[0].size() > path[1].size()) return path[0]; return path[1]; } if(are_connected({path[0][0]}, {path[1][0]})){ reverse(path[0].begin(), path[0].end()); path[0].insert(path[0].end(), path[1].begin(), path[1].end()); return path[0]; } if(are_connected({path[0][0]}, {path[1][path[1].size()-1]})){ path[1].insert(path[1].end(), path[0].begin(), path[0].end()); return path[1]; } if(are_connected({path[0][path[0].size()-1]}, {path[1][0]})){ path[0].insert(path[0].end(), path[1].begin(), path[1].end()); return path[0]; } // jetzt wissen wir das path[0].begin - path[0].end // jetzt wissen wir das path[1].begin - path[1].end // und die pfade sind nicht disjoint // eine node in path[0] finden die mit path[1] verbunden ist // find i int li = 0, ri = path[0].size()-1; while(li<ri){ int mi = (li + ri) / 2; vector<int> sub(path[0].begin(), path[0].begin()+mi+1); if(are_connected(sub, path[1])){ ri = mi; }else{ li = mi + 1; } } int i = li; for(int j=0; j<path[1].size(); j++){ if(are_connected({path[0][i]}, {path[1][j]})){ vector<int> ans; ans.insert(ans.end(), path[0].begin() + i + 1, path[0].end()); ans.insert(ans.end(), path[0].begin(), path[0].begin() + i + 1); ans.insert(ans.end(), path[1].begin() + j, path[1].end()); ans.insert(ans.end(), path[1].begin(), path[1].begin() + j); return ans; } } assert(false); }

컴파일 시 표준 에러 (stderr) 메시지

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int j=0; j<path[1].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...