Submission #844197

# Submission time Handle Problem Language Result Execution time Memory
844197 2023-09-05T11:07:13 Z gingers Longest Trip (IOI23_longesttrip) C++17
15 / 100
9 ms 600 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},{v1.front()})){
                    v1.insert(v1.begin(),i);
                    v2.insert(v2.begin(),i+1);
                } else {
                    v2.insert(v2.begin(),i);
                    v1.insert(v1.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 0 ms 344 KB Output is correct
2 Incorrect 2 ms 344 KB Incorrect
3 Halted 0 ms 0 KB -
# 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 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
# 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 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 5 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 5 ms 600 KB Output is correct
13 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 4 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 5 ms 600 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 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 4 ms 496 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 7 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 5 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
14 Correct 8 ms 344 KB Output is correct
15 Incorrect 3 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -