Submission #844202

# Submission time Handle Problem Language Result Execution time Memory
844202 2023-09-05T11:12:24 Z gingers Longest Trip (IOI23_longesttrip) C++17
100 / 100
9 ms 856 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> longest_trip(int N, int D){
    #define pb push_back
    vector <int> v1,v2;
    v1.pb(0);
    for (int i=1; i<N; i++){
        if (v2.empty()){
            if (are_connected({i},{v1.front()})){
                v1.insert(v1.begin(),i);
            } else {
                v2.pb(i);
            }
            continue;
        }
        if (i+1==N){
            bool a=are_connected({i},{v1.front()});
            bool b=are_connected({i},{v2.front()});
            if (a&&b){
                v2.insert(v2.begin(),i);
                for (int j:v2) v1.insert(v1.begin(),j);
                v2.clear();
            } else if (a){
                v1.insert(v1.begin(),i);
            } else if (b){
                v2.insert(v2.begin(),i);
            }
        } else {
            if (are_connected({i},{i+1})){
                if (are_connected({i},{v1.front()})){
                    v1.insert(v1.begin(),i);
                    v1.insert(v1.begin(),i+1);
                } else {
                    v2.insert(v2.begin(),i);
                    v2.insert(v2.begin(),i+1);
                }
                if (are_connected({v1.front()},{v2.front()})){
                    for (auto i:v2) v1.insert(v1.begin(),i);
                    v2.clear();
                }
            } else {
                if (are_connected({i},{v2.front()})&&are_connected({i+1},{v1.front()})){
                    v2.insert(v2.begin(),i);
                    v1.insert(v1.begin(),i+1);
                } else {
                    v1.insert(v1.begin(),i);
                    v2.insert(v2.begin(),i+1);
                }
            }
            i++;
        }
    }
    if (v2.empty()) return v1;
    if (!are_connected(v1,v2)){
        if (v1.size()>=v2.size()) return v1;
        return v2;
    }
    if (are_connected({v1.front()},{v2.back()})){
        for (int i:v1) v2.pb(i);
        return v2;
    }
    if (are_connected({v1.front()},{v2.front()})){
        for (int i:v2) v2.insert(v2.begin(),i);
        return v2;
    }
    if (are_connected({v2.front()},{v1.back()})){
        for (int i:v2) v1.pb(i);
        return v1;
    }
    vector <int> c1=v1;
    while (c1.size()>1){
        int tp=c1.size()/2;
        vector <int> tp1,tp2;
        for (int i=0; i<c1.size(); i++){
            if (i<tp) tp1.pb(c1[i]);
            else tp2.pb(c1[i]);
        }
        if (are_connected(tp1,v2)) c1=tp1;
        else c1=tp2;
    }
    vector <int> c2=v2;
    while (c2.size()>1){
        int tp=c2.size()/2;
        vector <int> tp1,tp2;
        for (int i=0; i<c2.size(); i++){
            if (i<tp) tp1.pb(c2[i]);
            else tp2.pb(c2[i]);
        }
        if (are_connected(c1,tp1)) c2=tp1;
        else c2=tp2;
    }
    vector <int> ret;
    int pos=0;
    for (int i=0; i<v1.size(); i++){
        if (v1[i]==c1[0]) pos=i;
    }
    for (int i=(pos+1)%v1.size(),cnt=0; cnt<v1.size(); i=(i+1)%v1.size(),cnt++){
        ret.pb(v1[i]);
    }
    pos=0;
    for (int i=0; i<v2.size(); i++){
        if (v2[i]==c2[0]) pos=i;
    }
    for (int i=pos,cnt=0; cnt<v2.size(); i=(i+1)%v2.size(),cnt++){
        ret.pb(v2[i]);
    }
    return ret;
    #undef pb
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:75:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for (int i=0; i<c1.size(); i++){
      |                       ~^~~~~~~~~~
longesttrip.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int i=0; i<c2.size(); i++){
      |                       ~^~~~~~~~~~
longesttrip.cpp:95:20: 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<v1.size(); i++){
      |                   ~^~~~~~~~~~
longesttrip.cpp:98:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for (int i=(pos+1)%v1.size(),cnt=0; cnt<v1.size(); i=(i+1)%v1.size(),cnt++){
      |                                         ~~~^~~~~~~~~~
longesttrip.cpp:102:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for (int i=0; i<v2.size(); i++){
      |                   ~^~~~~~~~~~
longesttrip.cpp:105:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for (int i=pos,cnt=0; cnt<v2.size(); i=(i+1)%v2.size(),cnt++){
      |                           ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 9 ms 596 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 5 ms 344 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 7 ms 504 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 5 ms 344 KB Output is correct
33 Correct 6 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 5 ms 600 KB Output is correct
37 Correct 6 ms 344 KB Output is correct
38 Correct 7 ms 596 KB Output is correct
39 Correct 5 ms 344 KB Output is correct
40 Correct 7 ms 436 KB Output is correct
41 Correct 5 ms 344 KB Output is correct
42 Correct 5 ms 496 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 6 ms 344 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 9 ms 344 KB Output is correct
47 Correct 7 ms 344 KB Output is correct
48 Correct 8 ms 344 KB Output is correct
49 Correct 7 ms 344 KB Output is correct
50 Correct 6 ms 436 KB Output is correct
51 Correct 7 ms 436 KB Output is correct
52 Correct 7 ms 344 KB Output is correct
53 Correct 6 ms 344 KB Output is correct
54 Correct 6 ms 344 KB Output is correct
55 Correct 6 ms 344 KB Output is correct
56 Correct 5 ms 440 KB Output is correct
57 Correct 6 ms 600 KB Output is correct
58 Correct 7 ms 600 KB Output is correct
59 Correct 7 ms 600 KB Output is correct
60 Correct 7 ms 440 KB Output is correct
61 Correct 7 ms 344 KB Output is correct
62 Correct 6 ms 600 KB Output is correct
63 Correct 8 ms 604 KB Output is correct
64 Correct 9 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 4 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Correct 8 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 5 ms 600 KB Output is correct
21 Correct 6 ms 496 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 8 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 6 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 8 ms 344 KB Output is correct
36 Correct 7 ms 344 KB Output is correct
37 Correct 6 ms 436 KB Output is correct
38 Correct 7 ms 432 KB Output is correct
39 Correct 6 ms 344 KB Output is correct
40 Correct 6 ms 596 KB Output is correct
41 Correct 6 ms 344 KB Output is correct
42 Correct 6 ms 600 KB Output is correct
43 Correct 5 ms 344 KB Output is correct
44 Correct 5 ms 344 KB Output is correct
45 Correct 5 ms 344 KB Output is correct
46 Correct 6 ms 344 KB Output is correct
47 Correct 6 ms 344 KB Output is correct
48 Correct 6 ms 344 KB Output is correct
49 Correct 6 ms 600 KB Output is correct
50 Correct 6 ms 344 KB Output is correct
51 Correct 6 ms 344 KB Output is correct
52 Correct 5 ms 344 KB Output is correct
53 Correct 5 ms 344 KB Output is correct
54 Correct 5 ms 344 KB Output is correct
55 Correct 6 ms 344 KB Output is correct
56 Correct 7 ms 344 KB Output is correct
57 Correct 7 ms 344 KB Output is correct
58 Correct 6 ms 344 KB Output is correct
59 Correct 6 ms 344 KB Output is correct
60 Correct 7 ms 600 KB Output is correct
61 Correct 6 ms 600 KB Output is correct
62 Correct 5 ms 440 KB Output is correct
63 Correct 7 ms 500 KB Output is correct
64 Correct 7 ms 600 KB Output is correct
65 Correct 8 ms 600 KB Output is correct
66 Correct 7 ms 692 KB Output is correct
67 Correct 7 ms 344 KB Output is correct
68 Correct 7 ms 688 KB Output is correct
69 Correct 7 ms 440 KB Output is correct
70 Correct 6 ms 436 KB Output is correct
71 Correct 6 ms 600 KB Output is correct
72 Correct 7 ms 604 KB Output is correct
73 Correct 7 ms 440 KB Output is correct
74 Correct 7 ms 436 KB Output is correct
75 Correct 7 ms 344 KB Output is correct
76 Correct 6 ms 344 KB Output is correct
77 Correct 6 ms 440 KB Output is correct
78 Correct 7 ms 600 KB Output is correct
79 Correct 6 ms 856 KB Output is correct
80 Correct 6 ms 600 KB Output is correct
81 Correct 6 ms 344 KB Output is correct
82 Correct 7 ms 344 KB Output is correct