Submission #841329

# Submission time Handle Problem Language Result Execution time Memory
841329 2023-09-01T13:56:31 Z NicolaAbusaad2014 Longest Trip (IOI23_longesttrip) C++17
40 / 100
21 ms 516 KB
#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

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 time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 6 ms 208 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 7 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 256 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 6 ms 336 KB Output is correct
5 Correct 6 ms 336 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct
8 Correct 7 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 10 ms 336 KB Output is correct
11 Correct 8 ms 336 KB Output is correct
12 Correct 9 ms 336 KB Output is correct
13 Correct 8 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 9 ms 336 KB Output is correct
5 Correct 7 ms 312 KB Output is correct
6 Correct 14 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 10 ms 336 KB Output is correct
11 Correct 7 ms 336 KB Output is correct
12 Correct 10 ms 336 KB Output is correct
13 Correct 10 ms 336 KB Output is correct
14 Correct 20 ms 208 KB Output is correct
15 Correct 14 ms 208 KB Output is correct
16 Correct 14 ms 208 KB Output is correct
17 Correct 11 ms 208 KB Output is correct
18 Correct 5 ms 208 KB Output is correct
19 Correct 12 ms 260 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 8 ms 336 KB Output is correct
22 Correct 6 ms 336 KB Output is correct
23 Correct 10 ms 336 KB Output is correct
24 Correct 8 ms 336 KB Output is correct
25 Correct 16 ms 208 KB Output is correct
26 Correct 16 ms 208 KB Output is correct
27 Correct 16 ms 332 KB Output is correct
28 Correct 17 ms 208 KB Output is correct
29 Correct 17 ms 208 KB Output is correct
30 Correct 10 ms 208 KB Output is correct
31 Correct 13 ms 208 KB Output is correct
32 Correct 18 ms 208 KB Output is correct
33 Correct 10 ms 208 KB Output is correct
34 Correct 16 ms 208 KB Output is correct
35 Correct 17 ms 208 KB Output is correct
36 Correct 11 ms 336 KB Output is correct
37 Correct 21 ms 464 KB Output is correct
38 Correct 14 ms 336 KB Output is correct
39 Correct 17 ms 336 KB Output is correct
40 Correct 14 ms 336 KB Output is correct
41 Correct 14 ms 516 KB Output is correct
42 Correct 16 ms 460 KB Output is correct
43 Correct 17 ms 336 KB Output is correct
44 Correct 19 ms 344 KB Output is correct
45 Correct 14 ms 208 KB Output is correct
46 Correct 11 ms 208 KB Output is correct
47 Correct 10 ms 208 KB Output is correct
48 Correct 13 ms 208 KB Output is correct
49 Correct 14 ms 208 KB Output is correct
50 Correct 13 ms 208 KB Output is correct
51 Correct 18 ms 208 KB Output is correct
52 Correct 12 ms 304 KB Output is correct
53 Correct 9 ms 208 KB Output is correct
54 Correct 11 ms 208 KB Output is correct
55 Correct 13 ms 208 KB Output is correct
56 Correct 10 ms 336 KB Output is correct
57 Correct 12 ms 356 KB Output is correct
58 Correct 16 ms 336 KB Output is correct
59 Correct 15 ms 360 KB Output is correct
60 Correct 19 ms 336 KB Output is correct
61 Correct 10 ms 368 KB Output is correct
62 Correct 18 ms 336 KB Output is correct
63 Correct 20 ms 328 KB Output is correct
64 Correct 11 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 10 ms 312 KB Output is correct
5 Correct 10 ms 336 KB Output is correct
6 Correct 13 ms 208 KB Output is correct
7 Correct 12 ms 208 KB Output is correct
8 Correct 12 ms 304 KB Output is correct
9 Correct 10 ms 208 KB Output is correct
10 Correct 8 ms 336 KB Output is correct
11 Correct 11 ms 312 KB Output is correct
12 Correct 8 ms 336 KB Output is correct
13 Correct 7 ms 336 KB Output is correct
14 Correct 13 ms 208 KB Output is correct
15 Correct 12 ms 208 KB Output is correct
16 Incorrect 2 ms 208 KB Incorrect
17 Halted 0 ms 0 KB -