답안 #1008697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008697 2024-06-26T16:46:19 Z De3b0o 가장 긴 여행 (IOI23_longesttrip) C++17
25 / 100
9 ms 444 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(p1.size()>p2.size())
        {
            for(auto it : p1)
                trnbo.pb(it);
        }
        else
        {
            for(auto it : p2)
                trnbo.pb(it);
        }
        return 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:90: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]
   90 |             if(are_connected({p1[0]},{p2[0]}))
      |                                             ^
longesttrip.cpp:90: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:90: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:90: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:97: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]
   97 |             else if(are_connected({p1[0]},{p2[p2.size()-1]}))
      |                                                            ^
longesttrip.cpp:97: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:97: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:97: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:104: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]
  104 |             else if(are_connected({p1[p1.size()-1]},{p2[0]}))
      |                                                            ^
longesttrip.cpp:104: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:104: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:104: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:111: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]
  111 |             else if(are_connected({p1[p1.size()-1]},{p2[p2.size()-1]}))
      |                                                                      ^
longesttrip.cpp:111: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:111: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:111: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:136: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]
  136 |                 vector<int> v1 = {p1[r]};
      |                                        ^
longesttrip.cpp:136: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:151:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  151 |                 for(int j = f+1 ; p1.size()>j ; j++)
      |                                   ~~~~~~~~~^~
longesttrip.cpp:156:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  156 |                 for(int j = s+1 ; p2.size()>j ; j++)
      |                                   ~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 5 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 3 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 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 5 ms 440 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 5 ms 344 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 5 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 7 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 5 ms 344 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 5 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 6 ms 344 KB Output is correct
33 Correct 5 ms 344 KB Output is correct
34 Correct 5 ms 344 KB Output is correct
35 Correct 5 ms 344 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 7 ms 344 KB Output is correct
38 Correct 8 ms 344 KB Output is correct
39 Correct 7 ms 444 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 6 ms 428 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 6 ms 428 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 6 ms 344 KB Output is correct
48 Correct 7 ms 344 KB Output is correct
49 Correct 8 ms 344 KB Output is correct
50 Correct 4 ms 344 KB Output is correct
51 Correct 7 ms 344 KB Output is correct
52 Correct 6 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 5 ms 424 KB Output is correct
56 Correct 5 ms 344 KB Output is correct
57 Correct 6 ms 344 KB Output is correct
58 Correct 6 ms 344 KB Output is correct
59 Correct 5 ms 344 KB Output is correct
60 Correct 9 ms 344 KB Output is correct
61 Correct 6 ms 344 KB Output is correct
62 Correct 7 ms 440 KB Output is correct
63 Correct 6 ms 428 KB Output is correct
64 Correct 8 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -