Submission #1008693

# Submission time Handle Problem Language Result Execution time Memory
1008693 2024-06-26T16:44:06 Z De3b0o Longest Trip (IOI23_longesttrip) C++17
15 / 100
9 ms 600 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
#include<random>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)

using namespace std;

std::vector<int> longest_trip(int N, int D)
{
    ll n = N;
    vector<ll> v;
    for(int i = 0 ; n>i ; i++)
        v.pb(i);
    random_shuffle(v.begin(),v.end());
    ll l1 = v[0] , l2 = v[1];
    vector<ll> p1 , p2;
    p1.pb(v[0]);
    p2.pb(v[1]);
    bool g1 = 0;
    for(int i = 2 ; n>i ; i++)
    {
        if(are_connected({l1},{v[i]}))
        {
            p1.pb(v[i]);
            l1=v[i];
            g1 = 0;
        }
        else
        {
            if(g1)
            {
                p2.pb(v[i]);
                l2=v[i];
            }
            else
            {
                if(are_connected({l2},{v[i]}))
                {
                    p2.pb(v[i]);
                    l2=v[i];
                    g1=1;
                }
                else
                {
                    for(int j = p2.size()-1 ; j>=0 ; j--)
                        p1.pb(p2[j]);
                    l1 = p1[p1.size()-1];
                    p2.clear();
                    p2.pb(v[i]);
                    l2=v[i];
                }
            }
        }
    }
        vector<int> trnbo;
        if(p2.size()==0)
        {
            for(auto it : p1)
                trnbo.pb(it);
        }
        else
        {
            if(are_connected({p1[0]},{p2[0]}))
            {
                for(int j = p1.size()-1 ; j>=0 ; j--)
                    trnbo.pb(p1[j]);
                for(auto it : p2)
                    trnbo.pb(it);
            }
            else if(are_connected({p1[0]},{p2[p2.size()-1]}))
            {
                for(int j = p1.size()-1 ; j>=0 ; j--)
                    trnbo.pb(p1[j]);
                for(int j = p2.size()-1 ; j>=0 ; j--)
                    trnbo.pb(p2[j]);
            }
            else if(are_connected({p1[p1.size()-1]},{p2[0]}))
            {
                for(auto it : p1)
                    trnbo.pb(it);
                for(auto it : p2)
                    trnbo.pb(it);
            }
            else if(are_connected({p1[p1.size()-1]},{p2[p2.size()-1]}))
            {
                for(auto it : p1)
                    trnbo.pb(it);
                for(int j = p2.size()-1 ; j>=0 ; j--)
                    trnbo.pb(p2[j]);
            }
            else
            {
                ll l = 0 , r = p1.size()-1;
                vector<int> pp2;
                for(auto it : p2)
                    pp2.pb(it);
                while(l<=r)
                {
                    vector<int> v1;
                    for(int j = 0 ; mid>=j ; j++)
                        v1.pb(p1[j]);
                    if(are_connected(v1,pp2))
                        r=mid-1;
                    else
                        l=mid+1;
                }
                r++;
                ll f = r;
                vector<int> v1 = {p1[r]};
                l = 0;
                r = p2.size()-1;
                while(l<=r)
                {
                    vector<int> v2;
                    for(int j = 0 ; mid>=j ; j++)
                        v2.pb(p2[j]);
                    if(are_connected(v1,v2))
                        r=mid-1;
                    else
                        l=mid+1;
                }
                r++;
                ll s = r;
                for(int j = f+1 ; p1.size()>j ; j++)
                    trnbo.pb(p1[j]);
                for(int j = 0 ; f>=j ; j++)
                    trnbo.pb(p1[j]);
                trnbo.pb(p2[s]);
                for(int j = s+1 ; p2.size()>j ; j++)
                    trnbo.pb(p2[j]);
                for(int j = 0 ; s>j ; j++)
                    trnbo.pb(p2[j]);
            }
        }
    return trnbo;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:38:27: warning: narrowing conversion of 'l1' from 'long long int' to 'int' [-Wnarrowing]
   38 |         if(are_connected({l1},{v[i]}))
      |                           ^~
longesttrip.cpp:38:27: warning: narrowing conversion of 'l1' from 'long long int' to 'int' [-Wnarrowing]
longesttrip.cpp:38:37: warning: narrowing conversion of 'v.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   38 |         if(are_connected({l1},{v[i]}))
      |                                     ^
longesttrip.cpp:38:37: warning: narrowing conversion of 'v.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:53:35: warning: narrowing conversion of 'l2' from 'long long int' to 'int' [-Wnarrowing]
   53 |                 if(are_connected({l2},{v[i]}))
      |                                   ^~
longesttrip.cpp:53:35: warning: narrowing conversion of 'l2' from 'long long int' to 'int' [-Wnarrowing]
longesttrip.cpp:53:45: warning: narrowing conversion of 'v.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   53 |                 if(are_connected({l2},{v[i]}))
      |                                             ^
longesttrip.cpp:53:45: warning: narrowing conversion of 'v.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:79:45: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   79 |             if(are_connected({p1[0]},{p2[0]}))
      |                                             ^
longesttrip.cpp:79:45: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:79:45: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:79:45: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:86:60: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   86 |             else if(are_connected({p1[0]},{p2[p2.size()-1]}))
      |                                                            ^
longesttrip.cpp:86:60: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:86:60: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[]((p2.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:86:60: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[]((p2.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:93:60: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[]((p1.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   93 |             else if(are_connected({p1[p1.size()-1]},{p2[0]}))
      |                                                            ^
longesttrip.cpp:93:60: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[]((p1.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:93:60: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:93:60: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:100:70: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[]((p1.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
  100 |             else if(are_connected({p1[p1.size()-1]},{p2[p2.size()-1]}))
      |                                                                      ^
longesttrip.cpp:100:70: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[]((p1.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:100:70: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[]((p2.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:100:70: warning: narrowing conversion of 'p2.std::vector<long long int>::operator[]((p2.std::vector<long long int>::size() - 1))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:125:40: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)r))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
  125 |                 vector<int> v1 = {p1[r]};
      |                                        ^
longesttrip.cpp:125:40: warning: narrowing conversion of 'p1.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)r))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:140:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  140 |                 for(int j = f+1 ; p1.size()>j ; j++)
      |                                   ~~~~~~~~~^~
longesttrip.cpp:145:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  145 |                 for(int j = s+1 ; p2.size()>j ; j++)
      |                                   ~~~~~~~~~^~
# 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 Correct 5 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 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 6 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 7 ms 344 KB Output is correct
10 Correct 7 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 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 5 ms 344 KB Output is correct
5 Correct 6 ms 600 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 6 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 5 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
14 Incorrect 0 ms 344 KB Incorrect
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 6 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 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Incorrect 1 ms 344 KB Incorrect
15 Halted 0 ms 0 KB -