Submission #1007212

# Submission time Handle Problem Language Result Execution time Memory
1007212 2024-06-24T13:16:55 Z Amr Longest Trip (IOI23_longesttrip) C++17
0 / 100
1 ms 344 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define sz size()
#define all(x) (x).begin(), (x).end()
vector<int> v1,v2;
vector<int> go(ll x, ll y)
{
    if(x) reverse(all(v1));
    if(y) reverse(all(v2));
    for(int i = 0; i < v2.sz; i++) v1.push_back(v2[i]);
    return v1;
}
std::vector<int> longest_trip(int N, int D)
{

    v1.push_back(0);
    for(int i = 1; i < N; i++)
    {
        bool bo = are_connected({v1.back()},{i});
        if(bo==1) v1.push_back(i);
        else
        {
            if(v2.sz==0) v2.push_back(i);
            else
            {
                bo = are_connected({v2.back()},{i});
                if(bo==1) v2.push_back(i);
                else
                {
                    for(int i = 0; i < v2.sz; i++) v1.push_back(v2[i]); v2.clear();
                    v2.push_back(i);
                }
            }
        }
    }
    if(v2.sz==0) return v1;
    bool b1 = are_connected({v1[0]},{v2[0]});
    bool b2 = are_connected({v1[0]},{v2.back()});
    bool b3 = are_connected({v1.back()},{v2[0]});
    bool b4 = are_connected({v1.back()},{v2.back()});

    if(b1)
    {
        return go(1,0);
    }
    else if(b2)
    {
        return go(1,1);
    }
    else if(b3)
    {
        return go(0,0);
    }
    else if(b4)
    {
        return go(0,1);
    }
    // not connecteed
    bool both = are_connected(v1,v2);
    if(1)
    {
        if(v1.sz>v2.sz) return v1; else return v2;
    }
    // connected

}

Compilation message

longesttrip.cpp: In function 'std::vector<int> go(ll, ll)':
longesttrip.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < v2.sz; i++) v1.push_back(v2[i]);
      |                      ^
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:35:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |                     for(int i = 0; i < v2.sz; i++) v1.push_back(v2[i]); v2.clear();
      |                                      ^
longesttrip.cpp:35:21: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   35 |                     for(int i = 0; i < v2.sz; i++) v1.push_back(v2[i]); v2.clear();
      |                     ^~~
longesttrip.cpp:35:73: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   35 |                     for(int i = 0; i < v2.sz; i++) v1.push_back(v2[i]); v2.clear();
      |                                                                         ^~
longesttrip.cpp:64:10: warning: unused variable 'both' [-Wunused-variable]
   64 |     bool both = are_connected(v1,v2);
      |          ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB invalid array
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -