Submission #841329

#TimeUsernameProblemLanguageResultExecution timeMemory
841329NicolaAbusaad2014Longest Trip (IOI23_longesttrip)C++17
40 / 100
21 ms516 KiB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;
#define all(x) x.begin(),x.end()

vector<int>join(vector<int>&A,vector<int>&B)
{
    vector<int>ret=A;
    for(int i=0;i<B.size();i++){
        ret.push_back(B[i]);
    }
    return ret;
}
bool are_connected(int a,int b)
{
    return are_connected(vector<int>(1,a),vector<int>(1,b));
}
std::vector<int> longest_trip(int N, int D)
{
    vector<vector<int> >path(N);
    for(int i=0;i<N;i++){
        path[i].push_back(i);
    }
    while(path.size()>2){
        int sz=path.size();
        vector<int>A=path[sz-1],B=path[sz-2],C=path[sz-3];
        if(are_connected(A.back(),B[0])){
            path.pop_back();
            path.pop_back();
            path.push_back(join(A,B));
            continue;
        }
        if(are_connected(A.back(),C[0])){
            path.pop_back();
            path.pop_back();
            path.pop_back();
            path.push_back(join(A,C));
            path.push_back(B);
            continue;
        }
        path.pop_back();
        path.pop_back();
        path.pop_back();
        path.push_back(A);
        reverse(all(B));
        path.push_back(join(B,C));
    }
    if(are_connected(path[0][0],path[1][0])){
        reverse(all(path[0]));
        return join(path[0],path[1]);
    }
    if(are_connected(path[0][0],path[1].back())){
        return join(path[1],path[0]);
    }
    if(are_connected(path[0].back(),path[1][0])){
        return join(path[0],path[1]);
    }
    if(are_connected(path[0].back(),path[1].back())){
        reverse(all(path[1]));
        return join(path[0],path[1]);
    }
    if(path[0].size()>=path[1].size()){
        return path[0];
    }
    return path[1];
}

Compilation message (stderr)

longesttrip.cpp: In function 'std::vector<int> join(std::vector<int>&, std::vector<int>&)':
longesttrip.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<B.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...