답안 #1008638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008638 2024-06-26T16:08:16 Z De3b0o 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
1 ms 344 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_device rd;
    mt19937 g(rd());
    shuffle(v.begin(),v.end(),g);
    ll l1 = v[0] , l2 = v[1];
    vector<ll> p1 , p2;
    bool g1 = 0;
    for(int i = 2 ; n>i ; i++)
    {
        if(are_connected({l1},{v[i]}))
        {
            p1.pb(v[i]);
            l1=v[i];
        }
        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 = p2[0];
                    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:52:35: warning: narrowing conversion of 'l2' from 'long long int' to 'int' [-Wnarrowing]
   52 |                 if(are_connected({l2},{v[i]}))
      |                                   ^~
longesttrip.cpp:52:35: warning: narrowing conversion of 'l2' from 'long long int' to 'int' [-Wnarrowing]
longesttrip.cpp:52: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]
   52 |                 if(are_connected({l2},{v[i]}))
      |                                             ^
longesttrip.cpp:52: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:77: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]
   77 |             if(are_connected({p1[0]},{p2[0]}))
      |                                             ^
longesttrip.cpp:77: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:77: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:77: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:84: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]
   84 |             else if(are_connected({p1[0]},{p2[p2.size()-1]}))
      |                                                            ^
longesttrip.cpp:84: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:84: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:84: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:91: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]
   91 |             else if(are_connected({p1[p1.size()-1]},{p2[0]}))
      |                                                            ^
longesttrip.cpp:91: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:91: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:91: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:98: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]
   98 |             else if(are_connected({p1[p1.size()-1]},{p2[p2.size()-1]}))
      |                                                                      ^
longesttrip.cpp:98: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:98: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:98: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:123: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]
  123 |                 vector<int> v1 = {p1[r]};
      |                                        ^
longesttrip.cpp:123: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:138:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  138 |                 for(int j = f+1 ; p1.size()>j ; j++)
      |                                   ~~~~~~~~~^~
longesttrip.cpp:143:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  143 |                 for(int j = s+1 ; p2.size()>j ; j++)
      |                                   ~~~~~~~~~^~
longesttrip.cpp:27:16: warning: control reaches end of non-void function [-Wreturn-type]
   27 |     vector<ll> v;
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
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 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Incorrect
2 Halted 0 ms 0 KB -