Submission #1038175

#TimeUsernameProblemLanguageResultExecution timeMemory
1038175aymanrsLongest Trip (IOI23_longesttrip)C++17
60 / 100
873 ms1116 KiB
#include "longesttrip.h" #include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; bool g[300][300] = {{false}}; bool ej[256] = {false}; pair<vector<int>,vector<int>> fl(const vector<int>& V){ memset(ej, 0, sizeof(ej)); queue<int> q;q.push(V[0]); ej[V[0]]=true; vector<int> a;a.push_back(V[0]); while(!q.empty()){ int t = q.front(); q.pop(); for(int j : V){ if(g[t][j] && !ej[j]){ ej[j]=true; q.push(j); a.push_back(j); } } } vector<int> b, c; if(a.size()<V.size()){ for(int i : V) if(!ej[i]) b.push_back(i); return {a,b}; } int i, j; for(i = 0;i < V.size();i++){ for(j = i+1;j < V.size();j++){ if(!g[V[i]][V[j]]) goto hoho; } } hoho: if(i >= V.size() || j >= V.size()) return {a, {}}; a.clear(); i=V[i];j=V[j]; for(int k : V){ if(k==i||k==j) continue; if(!g[k][j]) a.push_back(k); else if(!g[k][i]) c.push_back(k); else { b.push_back(k); } } if(b.empty()){ a.push_back(i); for(int& k : a){ for(int& l : c){ if(g[k][l]){ swap(k, a.back()); swap(l, c[0]); c.push_back(j); for(int x : c) a.push_back(x); return {a, {}}; } } } } auto L = fl(b); if(L.second.empty()){ a.push_back(i); for(int k : L.first) a.push_back(k); a.push_back(j); for(int k : c) a.push_back(k); return {a, {}}; } else { if(a.empty()){ L.first.push_back(i); for(int k : L.second) L.first.push_back(k); L.first.push_back(j); for(int k : c) L.first.push_back(k); return {L.first, {}}; } if(g[a[0]][L.first[0]]){ a.push_back(i); swap(a.back(), a[0]); for(int k : L.first) a.push_back(k); for(int k : a) L.second.push_back(k); L.second.push_back(j); for(int k : c) L.second.push_back(k); return {L.second, {}}; } else { a.push_back(i); swap(a.back(), a[0]); for(int k : L.second) a.push_back(k); for(int k : a) L.first.push_back(k); L.first.push_back(j); for(int k : c) L.first.push_back(k); return {L.first, {}}; } } } std::vector<int> longest_trip(int N, int D) { vector<int> V; for(int i = 0;i < N;i++) for(int j = 0;j < N;j++) g[i][j] = false; for(int i = 0;i < N;i++){ V.push_back(i); for(int j = i+1;j < N;j++){ if(are_connected({i}, {j})){ g[i][j]=g[j][i]=true; } } } auto L = fl(V); if(L.first.size()>=L.second.size()) return L.first; return L.second; }

Compilation message (stderr)

longesttrip.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > fl(const std::vector<int>&)':
longesttrip.cpp:30:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(i = 0;i < V.size();i++){
      |               ~~^~~~~~~~~~
longesttrip.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(j = i+1;j < V.size();j++){
      |                     ~~^~~~~~~~~~
longesttrip.cpp:36:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     if(i >= V.size() || j >= V.size()) return {a, {}};
      |        ~~^~~~~~~~~~~
longesttrip.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     if(i >= V.size() || j >= V.size()) return {a, {}};
      |                         ~~^~~~~~~~~~~
#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...