답안 #845786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845786 2023-09-06T15:34:16 Z leinad2 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
13 ms 600 KB
#include "longesttrip.h"

#include<bits/stdc++.h>
using namespace std;
int i, j, k, a, b, A[260][260], B[260];
vector<int> longest_trip(int N, int D)
{
    vector<int>v1, v2;
    v1.push_back(0);
    v2.push_back(1);
    bool flag=false;
    for(i=2;i<N;i++)
    {
        vector<int>X, Y, Z;
        X.push_back(v1.back());Y.push_back(i);Z.push_back(v2.back());
        if(are_connected(X, Y))v1.push_back(i),flag=false;
        else if(flag)v2.push_back(i);
        else if(are_connected(Z, Y))
        {
            flag=true;
            v2.push_back(i);
        }
        else
        {
            while(v2.size())
            {
                v1.push_back(v2.back());
                v2.pop_back();
            }
            v2.push_back(i);
        }
    }
    if(are_connected(v1, v2)==0)
    {
        if(v1.size()<v2.size())swap(v1, v2);
        return v1;
    }
    vector<int>X, Y, Z, W;
    X.push_back(v1.back());
    Z.push_back(v2[0]);W.push_back(v2.back());
    if(are_connected(X, Z))
    {
        for(auto p:v2)v1.push_back(p);
        for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
        assert(v1.size()==N);
        return v1;
    }
    if(are_connected(X, W))
    {
        while(v2.size())
        {
            v1.push_back(v2.back());
            v2.pop_back();
        }
        for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
        assert(v1.size()==N);
        return v1;
    }
    if(are_connected(X, v2))
    {
        int s=0, e=v2.size()-1;
        while(s<e)
        {
            int m=s+e>>1;
            vector<int>V;
            for(i=0;i<=m;i++)V.push_back(v2[i]);
            if(are_connected(X, V))e=m;
            else s=m+1;
        }
        for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
        for(i=0;i<s;i++)v1.push_back(v2[i]);
        for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
        assert(v1.size()==N);
        return v1;
    }
    Y.push_back(v1[0]);
    if(are_connected(Y, v2))
    {
        int s=0, e=v2.size()-1;
        while(s<e)
        {
            int m=s+e>>1;
            vector<int>V;
            for(i=0;i<=m;i++)V.push_back(v2[i]);
            if(are_connected(Y, V))e=m;
            else s=m+1;
        }
        reverse(v1.begin(), v1.end());
        for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
        for(i=0;i<s;i++)v1.push_back(v2[i]);
        for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
        assert(v1.size()==N);
        return v1;
    }
    int s=0, e=v1.size()-1;
    while(s<e)
    {
        int m=s+e>>1;
        vector<int>V;
        for(i=0;i<=m;i++)V.push_back(v1[i]);
        if(are_connected(V, v2))e=m;
        else s=m+1;
    }
    int ss=s;
    s=0, e=v2.size()-1;
    X[0]=v1[s];
    while(s<e)
    {
        int m=s+e>>1;
        vector<int>V;
        for(i=0;i<=m;i++)V.push_back(v2[i]);
        if(are_connected(X, V))e=m;
        else s=m+1;
    }
    vector<int>ans;
    for(i=ss-1;i>=0;i--)ans.push_back(v1[i]);
    for(i=v1.size()-1;i>=ss;i--)ans.push_back(v1[i]);
    for(i=s;i<v2.size();i++)ans.push_back(v2[i]);
    for(i=0;i<s;i++)ans.push_back(v2[i]);
    v1=v2;
        for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
        assert(v1.size()==N);
    return v2;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:3:
longesttrip.cpp:45:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |         assert(v1.size()==N);
      |                ~~~~~~~~~^~~
longesttrip.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:3:
longesttrip.cpp:56:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |         assert(v1.size()==N);
      |                ~~~~~~~~~^~~
longesttrip.cpp:64:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |             int m=s+e>>1;
      |                   ~^~
longesttrip.cpp:70:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
      |                 ~^~~~~~~~~~
longesttrip.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:3:
longesttrip.cpp:73:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |         assert(v1.size()==N);
      |                ~~~~~~~~~^~~
longesttrip.cpp:82:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |             int m=s+e>>1;
      |                   ~^~
longesttrip.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
      |                 ~^~~~~~~~~~
longesttrip.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:3:
longesttrip.cpp:92:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |         assert(v1.size()==N);
      |                ~~~~~~~~~^~~
longesttrip.cpp:98:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   98 |         int m=s+e>>1;
      |               ~^~
longesttrip.cpp:109:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  109 |         int m=s+e>>1;
      |               ~^~
longesttrip.cpp:118:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for(i=s;i<v2.size();i++)ans.push_back(v2[i]);
      |             ~^~~~~~~~~~
longesttrip.cpp:121:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |         for(i=0;i+1<v1.size();i++)assert(are_connected({v1[i]}, {v1[i+1]}));
      |                 ~~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from longesttrip.cpp:3:
longesttrip.cpp:122:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |         assert(v1.size()==N);
      |                ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 10 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 10 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 11 ms 344 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 12 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 9 ms 344 KB Output is correct
9 Correct 9 ms 600 KB Output is correct
10 Correct 8 ms 600 KB Output is correct
11 Correct 9 ms 344 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 8 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 9 ms 344 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 13 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 9 ms 448 KB Output is correct
10 Correct 8 ms 600 KB Output is correct
11 Correct 9 ms 344 KB Output is correct
12 Correct 9 ms 600 KB Output is correct
13 Correct 8 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 Runtime error 2 ms 600 KB Execution killed with signal 6
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 10 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Partially correct 10 ms 500 KB Output is partially correct
6 Correct 12 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 9 ms 344 KB Output is correct
9 Correct 9 ms 444 KB Output is correct
10 Partially correct 8 ms 444 KB Output is partially correct
11 Partially correct 9 ms 344 KB Output is partially correct
12 Partially correct 8 ms 344 KB Output is partially correct
13 Partially correct 8 ms 344 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 6 ms 344 KB Output is correct
16 Runtime error 2 ms 600 KB Execution killed with signal 6
17 Halted 0 ms 0 KB -