답안 #1063946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063946 2024-08-18T06:35:49 Z parsadox2 가장 긴 여행 (IOI23_longesttrip) C++17
70 / 100
78 ms 856 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 256;
int n , d;
bool in_path[N];

vector <int> maximal()
{
    for(int i = 0 ; i < n ; i++)
        in_path[i] = false;
    vector <int> vec;
    vec.push_back(0);
    in_path[0] = true;
    while(vec.size() < n)
    {
        vector <int> A; A.push_back(vec.back());
        vector <int> B;
        for(int i = 0 ; i < n ; i++)  if(!in_path[i])
            B.push_back(i);
        if(!are_connected(A , B))
            break;
        int low = 0 , high = B.size();
        while(high - low > 1)
        {
            int mid = (low + high) >> 1;
            vector <int> tmp;
            for(int i = low ; i < mid ; i++)
                tmp.push_back(B[i]);
            if(are_connected(A , tmp))
                high = mid;
            else
                low = mid;
        }
        in_path[B[low]] = true;
        vec.push_back(B[low]);
    }
    reverse(vec.begin() , vec.end());
    while(vec.size() < n)
    {
        vector <int> A;  A.push_back(vec.back());
        vector <int> B;
        for(int i = 0 ; i < n ; i++)  if(!in_path[i])
            B.push_back(i);
        if(!are_connected(A , B))
            break;
        int low = 0 , high = B.size();
        while(high - low > 1)
        {
            int mid = (low + high) >> 1;
            vector <int> tmp;
            for(int i = low ; i < mid ; i++)
                tmp.push_back(B[i]);
            if(are_connected(A , tmp))
                high = mid;
            else
                low = mid;
        }
        in_path[B[low]] = true;
        vec.push_back(B[low]);
    }
    return vec;
}

vector<int> longest_trip(int nn, int dd)
{
    n = nn;
    d = dd;
    vector <int> vec = maximal();
    vector <int> comp;
    for(int i = 0 ; i < n ; i++)  if(!in_path[i])
        comp.push_back(i);
    if(comp.empty())
        return vec;
    if(!are_connected(vec , comp))
    {
        if(vec.size() > comp.size())
            return vec;
        else
            return comp;
    }
    int low = 0 , high = vec.size();
    while(high - low > 1)
    {
        int mid = (low + high) >> 1;
        vector <int> tmp;
        for(int i = low ; i < mid ; i++)
            tmp.push_back(vec[i]);
        if(are_connected(tmp , comp))
            high = mid;
        else
            low = mid;
    }
    vector <int> res;
    for(int i = low + 1 ; i < vec.size() ; i++)
        res.push_back(vec[i]);
    for(int i = 0 ; i <= low ; i++)
        res.push_back(vec[i]);
    low = 0;  high = comp.size();
    vector <int> A;  A.push_back(res.back());
    while(high - low > 1)
    {
        int mid = (low + high) >> 1;
        vector <int> B;
        for(int i = low ; i < mid ; i++)
            B.push_back(comp[i]);
        if(are_connected(A , B))
            high = mid;
        else
            low = mid;
    }
    res.push_back(comp[low]);
    for(int i = 0 ; i < comp.size() ; i++)  if(i != low)
        res.push_back(comp[i]);
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> maximal()':
longesttrip.cpp:17:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |     while(vec.size() < n)
      |           ~~~~~~~~~~~^~~
longesttrip.cpp:41:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |     while(vec.size() < n)
      |           ~~~~~~~~~~~^~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:97:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i = low + 1 ; i < vec.size() ; i++)
      |                           ~~^~~~~~~~~~~~
longesttrip.cpp:115:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |     for(int i = 0 ; i < comp.size() ; i++)  if(i != low)
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 12 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 28 ms 344 KB Output is correct
4 Correct 35 ms 344 KB Output is correct
5 Correct 57 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 28 ms 344 KB Output is correct
4 Correct 45 ms 344 KB Output is correct
5 Correct 56 ms 344 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 32 ms 344 KB Output is correct
9 Correct 35 ms 344 KB Output is correct
10 Correct 51 ms 344 KB Output is correct
11 Correct 56 ms 600 KB Output is correct
12 Correct 51 ms 464 KB Output is correct
13 Correct 57 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 24 ms 344 KB Output is correct
4 Correct 45 ms 344 KB Output is correct
5 Correct 53 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 14 ms 344 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 34 ms 344 KB Output is correct
10 Correct 54 ms 464 KB Output is correct
11 Correct 63 ms 712 KB Output is correct
12 Correct 74 ms 600 KB Output is correct
13 Correct 48 ms 344 KB Output is correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 20 ms 344 KB Output is correct
17 Correct 32 ms 344 KB Output is correct
18 Correct 35 ms 344 KB Output is correct
19 Correct 32 ms 344 KB Output is correct
20 Correct 35 ms 344 KB Output is correct
21 Correct 67 ms 700 KB Output is correct
22 Correct 67 ms 344 KB Output is correct
23 Correct 53 ms 344 KB Output is correct
24 Correct 61 ms 344 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 12 ms 344 KB Output is correct
28 Correct 18 ms 344 KB Output is correct
29 Correct 14 ms 344 KB Output is correct
30 Correct 27 ms 344 KB Output is correct
31 Correct 23 ms 344 KB Output is correct
32 Correct 20 ms 344 KB Output is correct
33 Correct 38 ms 344 KB Output is correct
34 Correct 35 ms 344 KB Output is correct
35 Correct 38 ms 344 KB Output is correct
36 Correct 61 ms 464 KB Output is correct
37 Correct 53 ms 344 KB Output is correct
38 Correct 60 ms 440 KB Output is correct
39 Correct 51 ms 344 KB Output is correct
40 Correct 38 ms 344 KB Output is correct
41 Correct 32 ms 600 KB Output is correct
42 Correct 34 ms 344 KB Output is correct
43 Correct 33 ms 344 KB Output is correct
44 Correct 41 ms 344 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 9 ms 344 KB Output is correct
47 Correct 15 ms 344 KB Output is correct
48 Correct 13 ms 344 KB Output is correct
49 Correct 14 ms 344 KB Output is correct
50 Correct 39 ms 344 KB Output is correct
51 Correct 27 ms 344 KB Output is correct
52 Correct 25 ms 344 KB Output is correct
53 Correct 43 ms 344 KB Output is correct
54 Correct 32 ms 344 KB Output is correct
55 Correct 29 ms 344 KB Output is correct
56 Correct 71 ms 344 KB Output is correct
57 Correct 67 ms 344 KB Output is correct
58 Correct 50 ms 344 KB Output is correct
59 Correct 48 ms 344 KB Output is correct
60 Correct 62 ms 692 KB Output is correct
61 Correct 42 ms 344 KB Output is correct
62 Correct 51 ms 600 KB Output is correct
63 Correct 48 ms 344 KB Output is correct
64 Correct 55 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 24 ms 344 KB Output is correct
4 Partially correct 47 ms 344 KB Output is partially correct
5 Partially correct 51 ms 600 KB Output is partially correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 29 ms 344 KB Output is correct
9 Partially correct 39 ms 344 KB Output is partially correct
10 Partially correct 55 ms 344 KB Output is partially correct
11 Partially correct 66 ms 856 KB Output is partially correct
12 Partially correct 62 ms 472 KB Output is partially correct
13 Partially correct 59 ms 344 KB Output is partially correct
14 Correct 10 ms 344 KB Output is correct
15 Correct 13 ms 344 KB Output is correct
16 Correct 16 ms 344 KB Output is correct
17 Correct 31 ms 344 KB Output is correct
18 Correct 35 ms 344 KB Output is correct
19 Partially correct 35 ms 344 KB Output is partially correct
20 Partially correct 46 ms 344 KB Output is partially correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 8 ms 344 KB Output is correct
23 Correct 13 ms 344 KB Output is correct
24 Correct 14 ms 344 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 45 ms 344 KB Output is correct
27 Correct 21 ms 344 KB Output is correct
28 Correct 18 ms 344 KB Output is correct
29 Partially correct 32 ms 444 KB Output is partially correct
30 Partially correct 33 ms 344 KB Output is partially correct
31 Partially correct 35 ms 344 KB Output is partially correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 17 ms 344 KB Output is correct
35 Correct 11 ms 344 KB Output is correct
36 Correct 18 ms 344 KB Output is correct
37 Correct 39 ms 344 KB Output is correct
38 Correct 24 ms 344 KB Output is correct
39 Correct 24 ms 344 KB Output is correct
40 Partially correct 36 ms 340 KB Output is partially correct
41 Partially correct 41 ms 344 KB Output is partially correct
42 Partially correct 46 ms 344 KB Output is partially correct
43 Partially correct 53 ms 344 KB Output is partially correct
44 Partially correct 78 ms 716 KB Output is partially correct
45 Partially correct 56 ms 344 KB Output is partially correct
46 Partially correct 59 ms 344 KB Output is partially correct
47 Partially correct 50 ms 344 KB Output is partially correct
48 Partially correct 59 ms 696 KB Output is partially correct
49 Partially correct 60 ms 460 KB Output is partially correct
50 Partially correct 49 ms 600 KB Output is partially correct
51 Partially correct 32 ms 344 KB Output is partially correct
52 Partially correct 33 ms 596 KB Output is partially correct
53 Partially correct 39 ms 616 KB Output is partially correct
54 Partially correct 33 ms 344 KB Output is partially correct
55 Partially correct 29 ms 344 KB Output is partially correct
56 Partially correct 56 ms 452 KB Output is partially correct
57 Partially correct 41 ms 344 KB Output is partially correct
58 Partially correct 35 ms 344 KB Output is partially correct
59 Partially correct 27 ms 344 KB Output is partially correct
60 Partially correct 34 ms 344 KB Output is partially correct
61 Partially correct 34 ms 344 KB Output is partially correct
62 Partially correct 57 ms 344 KB Output is partially correct
63 Partially correct 68 ms 344 KB Output is partially correct
64 Partially correct 49 ms 856 KB Output is partially correct
65 Partially correct 53 ms 344 KB Output is partially correct
66 Partially correct 38 ms 600 KB Output is partially correct
67 Partially correct 38 ms 344 KB Output is partially correct
68 Partially correct 49 ms 600 KB Output is partially correct
69 Partially correct 50 ms 344 KB Output is partially correct
70 Partially correct 51 ms 676 KB Output is partially correct
71 Partially correct 47 ms 600 KB Output is partially correct
72 Partially correct 46 ms 344 KB Output is partially correct
73 Partially correct 38 ms 344 KB Output is partially correct
74 Partially correct 47 ms 592 KB Output is partially correct
75 Partially correct 42 ms 344 KB Output is partially correct
76 Partially correct 43 ms 344 KB Output is partially correct
77 Partially correct 67 ms 708 KB Output is partially correct
78 Partially correct 60 ms 600 KB Output is partially correct
79 Partially correct 55 ms 344 KB Output is partially correct
80 Partially correct 41 ms 340 KB Output is partially correct
81 Partially correct 56 ms 592 KB Output is partially correct
82 Partially correct 53 ms 600 KB Output is partially correct