답안 #847576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847576 2023-09-10T01:45:34 Z ibm2006 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
14 ms 692 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
ll n,i,j,k,s,t,x,y,z,w;
deque<ll> dq1,dq2;
vector<ll>v;
pair<ll,ll> p;
pair<ll,ll> inv(pair<ll,ll> p)
{
    return {p.second,p.first};
}
pair<ll,ll> adj(vector<ll> a,vector<ll> b)
{
    ll k=0;
    if(a.size()<b.size())
        {swap(a,b);  k=1;}
    if(a.size()==1&&b.size()==1)
    return {a[0],b[0]};
    vector<ll>c;
    for(i=0;i<a.size()/2;i++)
        c.push_back(a[i]);
    if(are_connected(c,b))
    {
        if(k==1)
        {
            return inv(adj(c,b));
        }
        else
            return adj(c,b);
    }
    else
    {
        c.clear();
        for(i=a.size()/2;i<a.size();i++)
            c.push_back(a[i]);
        if(k==1)
        {
            return inv(adj(c,b));
        }
        else
            return adj(c,b);
    }
}
vector<ll> vectorize(deque<ll> d)
{
    ll i;
    vector<ll> v;
    for(i=0;i<d.size();i++)
        v.push_back(d[i]);
    return v;
}
void combine()
{
    for(auto x:dq2)
        dq1.push_front(x);
    dq2.clear();
}
void answer()
{
    v.clear();
    for(i=0;i<dq1.size();i++)
    {
        v.push_back(dq1[i]);
    }
}
void init()
{
    dq1.clear();
    dq2.clear();
    v.clear();
    s=0;
    t=0;
}
vector<ll> longest_trip(ll N, ll D)
{
    init();
    n=N;
    dq1.push_back(0);
    dq2.push_back(1);
    for(i=2;i<n;i++)
    {
        if(are_connected({dq1[0]},{dq2[0]}))
        {
        combine();
        dq2.push_back(i);
        continue;
        }
        if(are_connected({dq1[0]},{i}))
            {
                dq1.push_front(i);
                continue;
            }
            dq2.push_front(i);
    }
    if(dq1.size()<dq2.size())
        swap(dq1,dq2);
        if(!are_connected(vectorize(dq1),vectorize(dq2)))
        {
            answer();
            return v;
        }
    if(dq2.size()==1)
    {
        if(are_connected({dq1[0]},{dq2[0]}))
        {
            dq1.push_front(dq2[0]);
        }
        else if(are_connected({dq1[dq1.size()-1]},{dq2[0]}))
            {
                dq1.push_back(dq2[0]);
            }
            else
            {
                for(i=0;i<dq1.size();i++)
                {
                    v.push_back(dq1[i]);
                }
                x=adj(vectorize(dq1),vectorize(dq2)).first;
                v.clear();
                v.push_back(dq2[0]);
                for(i=0;i<dq1.size();i++)
                {
                    if(dq1[i]==x)
                    {
                        t=1;
                    }
                    if(t==1)
                        v.push_back(dq1[i]);
                }
                for(i=0;i<dq1.size();i++)
                {
                    if(dq1[i]==x)
                        t=0;
                    if(t==1)
                        v.push_back(dq1[i]);
                }
                return v;
            }
        answer();
        return v;
    }
    if(are_connected({dq1[0]},{dq2[0]}))
        {
            for(auto x:dq2)
                dq1.push_front(x);
            answer();
            return v;
        }
        else if(are_connected({dq1[0]},{dq2[dq2.size()-1]}))
            {
                for(i=dq2.size()-1;i>=0;i--)
                {
                    dq1.push_front(dq2[i]);
                }
                answer();
               return v;
            }
    else if(are_connected({dq1[dq1.size()-1]},{dq2[0]}))
        {
            for(auto x:dq2)
                dq1.push_back(x);
            answer();
            return v;
        }
    else if(are_connected({dq1[dq1.size()-1]},{dq2[dq2.size()-1]}))
        {
            for(i=dq2.size()-1;i>=0;i--)
                {
                    dq1.push_back(dq2[i]);
                }
                answer();
               return v;
        }
    else
    {
        p=adj(vectorize(dq1),vectorize(dq2));
        x=p.first;
        y=p.second;
        t=0;
        for(i=0;i<dq1.size();i++)
        {
            if(t==1)
            {
                v.push_back(dq1[i]);
            }
            if(dq1[i]==x)
                t=1;
        }
        for(i=0;i<dq1.size();i++)
        {
            if(t==1)
                v.push_back(dq1[i]);
            if(dq1[i]==x)
                t=0;
        }
        for(i=0;i<dq2.size();i++)
        {
            if(dq2[i]==x)
                t=1;
            if(t==1)
            {
                v.push_back(dq2[i]);
            }
        }
        for(i=0;i<dq2.size();i++)
        {
            if(dq2[i]==x)
                t=0;
                if(t==1)
                    v.push_back(dq2[i]);
        }
        return v;
    }
}

Compilation message

longesttrip.cpp: In function 'std::pair<int, int> adj(std::vector<int>, std::vector<int>)':
longesttrip.cpp:21:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(i=0;i<a.size()/2;i++)
      |             ~^~~~~~~~~~~
longesttrip.cpp:35:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(i=a.size()/2;i<a.size();i++)
      |                          ~^~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> vectorize(std::deque<int>)':
longesttrip.cpp:49:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(i=0;i<d.size();i++)
      |             ~^~~~~~~~~
longesttrip.cpp: In function 'void answer()':
longesttrip.cpp:62:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(i=0;i<dq1.size();i++)
      |             ~^~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(ll, ll)':
longesttrip.cpp:96:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   96 |     if(dq1.size()<dq2.size())
      |     ^~
longesttrip.cpp:98:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   98 |         if(!are_connected(vectorize(dq1),vectorize(dq2)))
      |         ^~
longesttrip.cpp:115:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |                 for(i=0;i<dq1.size();i++)
      |                         ~^~~~~~~~~~~
longesttrip.cpp:122:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |                 for(i=0;i<dq1.size();i++)
      |                         ~^~~~~~~~~~~
longesttrip.cpp:131:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |                 for(i=0;i<dq1.size();i++)
      |                         ~^~~~~~~~~~~
longesttrip.cpp:181:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  181 |         for(i=0;i<dq1.size();i++)
      |                 ~^~~~~~~~~~~
longesttrip.cpp:190:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  190 |         for(i=0;i<dq1.size();i++)
      |                 ~^~~~~~~~~~~
longesttrip.cpp:197:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  197 |         for(i=0;i<dq2.size();i++)
      |                 ~^~~~~~~~~~~
longesttrip.cpp:206:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  206 |         for(i=0;i<dq2.size();i++)
      |                 ~^~~~~~~~~~~
longesttrip.cpp:208:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  208 |             if(dq2[i]==x)
      |             ^~
longesttrip.cpp:210:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  210 |                 if(t==1)
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 6 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 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 5 ms 344 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 7 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 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 9 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 5 ms 344 KB Output is correct
21 Correct 5 ms 600 KB Output is correct
22 Correct 5 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 6 ms 600 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 7 ms 596 KB Output is correct
27 Correct 8 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 8 ms 444 KB Output is correct
31 Correct 8 ms 440 KB Output is correct
32 Correct 9 ms 440 KB Output is correct
33 Correct 7 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 9 ms 344 KB Output is correct
36 Correct 7 ms 600 KB Output is correct
37 Correct 11 ms 692 KB Output is correct
38 Correct 8 ms 600 KB Output is correct
39 Correct 8 ms 600 KB Output is correct
40 Correct 10 ms 504 KB Output is correct
41 Correct 10 ms 600 KB Output is correct
42 Correct 9 ms 600 KB Output is correct
43 Correct 8 ms 344 KB Output is correct
44 Correct 10 ms 600 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 14 ms 512 KB Output is correct
47 Correct 8 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 7 ms 444 KB Output is correct
51 Correct 9 ms 440 KB Output is correct
52 Correct 9 ms 632 KB Output is correct
53 Correct 7 ms 600 KB Output is correct
54 Correct 9 ms 600 KB Output is correct
55 Correct 8 ms 600 KB Output is correct
56 Correct 5 ms 344 KB Output is correct
57 Correct 9 ms 604 KB Output is correct
58 Correct 9 ms 604 KB Output is correct
59 Correct 8 ms 604 KB Output is correct
60 Correct 10 ms 600 KB Output is correct
61 Correct 8 ms 604 KB Output is correct
62 Correct 9 ms 604 KB Output is correct
63 Correct 9 ms 604 KB Output is correct
64 Correct 9 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 600 KB Output is correct
2 Correct 6 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 5 ms 344 KB Output is correct
6 Correct 8 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 5 ms 604 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Incorrect 0 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -