답안 #839748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839748 2023-08-30T15:49:53 Z model_code 가장 긴 여행 (IOI23_longesttrip) C++17
70 / 100
197 ms 568 KB
// partially_correct/sol_andor_NlogN.cpp

#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> longest_trip(int N, int D)
{
    if (D == 3)
    {
        vector<int> sol(N);
        for (int i = 0; i < N; i++)
            sol[i] = i;
        return sol;
    }
    if (D == 2)
    {
        vector<int> sol = {0};
        deque<int> options;
        for (int i = 1; i < N; i++)
            options.push_back(i);
        int curr = 0;
        while (options.size() > 1)
        {
            if (!are_connected({curr}, {options.front()}))
            {
                options.push_back(options.front());
                options.pop_front();
            }
            sol.push_back(options.front());
            curr = options.front();
            options.pop_front();
        }
        if (are_connected({sol.back()}, {options.front()}))
            sol.push_back(options.front());
        else
            sol.insert(sol.begin(), options.front());
        return sol;
    }
    else
    {
        vector<int> sol = {0};
        vector<int> complementer;
        for (int i = 1; i < N; i++)
            complementer.push_back(i);
        while (sol.size() < N)
        {
            if (!are_connected(sol, complementer))
                break;
            int l = 0, r = complementer.size() - 1, m;
            while (l < r)
            {
                m = (l + r) / 2;
                vector<int> query_range(complementer.begin() + l, complementer.begin() + m + 1);
                if (are_connected(sol, query_range))
                    r = m;
                else
                    l = m + 1;
            }
            int next_item = complementer[r];
            complementer.erase(find(complementer.begin(), complementer.end(), next_item));
            if (are_connected({sol.back()}, {next_item}))
                sol.push_back(next_item);
            else if (are_connected({sol[0]}, {next_item}))
                sol.insert(sol.begin(), next_item);
            else
            {
                l = 1, r = sol.size() - 2;
                while (l < r)
                {
                    m = (l + r) / 2;
                    vector<int> query_range(sol.begin() + l, sol.begin() + m + 1);
                    if (are_connected(query_range, {next_item}))
                        r = m;
                    else
                        l = m + 1;
                }
                vector<int> new_sol;
                for (int i = r + 1; i < sol.size(); i++)
                    new_sol.push_back(sol[i]);
                for (int i = 0; i <= r; i++)
                    new_sol.push_back(sol[i]);
                new_sol.push_back(next_item);
                sol = new_sol;
            }
        }
        if (sol.size() >= (N + 1) / 2)
            return sol;
        else
            return complementer;
    }
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:47:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |         while (sol.size() < N)
      |                ~~~~~~~~~~~^~~
longesttrip.cpp:80:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                 for (int i = r + 1; i < sol.size(); i++)
      |                                     ~~^~~~~~~~~~~~
longesttrip.cpp:88:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |         if (sol.size() >= (N + 1) / 2)
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 43 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 7 ms 248 KB Output is correct
4 Correct 8 ms 252 KB Output is correct
5 Correct 9 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct
8 Correct 13 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 9 ms 208 KB Output is correct
11 Correct 8 ms 300 KB Output is correct
12 Correct 5 ms 244 KB Output is correct
13 Correct 8 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 208 KB Output is correct
2 Correct 33 ms 208 KB Output is correct
3 Correct 36 ms 208 KB Output is correct
4 Correct 110 ms 208 KB Output is correct
5 Correct 153 ms 352 KB Output is correct
6 Correct 19 ms 208 KB Output is correct
7 Correct 34 ms 208 KB Output is correct
8 Correct 64 ms 208 KB Output is correct
9 Correct 82 ms 208 KB Output is correct
10 Correct 145 ms 208 KB Output is correct
11 Correct 160 ms 384 KB Output is correct
12 Correct 159 ms 320 KB Output is correct
13 Correct 138 ms 296 KB Output is correct
14 Correct 9 ms 208 KB Output is correct
15 Correct 10 ms 208 KB Output is correct
16 Correct 46 ms 208 KB Output is correct
17 Correct 51 ms 256 KB Output is correct
18 Correct 78 ms 208 KB Output is correct
19 Correct 81 ms 308 KB Output is correct
20 Correct 86 ms 208 KB Output is correct
21 Correct 194 ms 316 KB Output is correct
22 Correct 164 ms 344 KB Output is correct
23 Correct 169 ms 324 KB Output is correct
24 Correct 158 ms 320 KB Output is correct
25 Correct 10 ms 208 KB Output is correct
26 Correct 11 ms 208 KB Output is correct
27 Correct 15 ms 256 KB Output is correct
28 Correct 43 ms 208 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 46 ms 300 KB Output is correct
31 Correct 43 ms 208 KB Output is correct
32 Correct 28 ms 208 KB Output is correct
33 Correct 109 ms 300 KB Output is correct
34 Correct 52 ms 308 KB Output is correct
35 Correct 61 ms 208 KB Output is correct
36 Correct 145 ms 328 KB Output is correct
37 Correct 130 ms 324 KB Output is correct
38 Correct 118 ms 324 KB Output is correct
39 Correct 125 ms 328 KB Output is correct
40 Correct 67 ms 308 KB Output is correct
41 Correct 95 ms 316 KB Output is correct
42 Correct 62 ms 316 KB Output is correct
43 Correct 90 ms 320 KB Output is correct
44 Correct 70 ms 440 KB Output is correct
45 Correct 18 ms 208 KB Output is correct
46 Correct 23 ms 208 KB Output is correct
47 Correct 34 ms 208 KB Output is correct
48 Correct 29 ms 208 KB Output is correct
49 Correct 19 ms 208 KB Output is correct
50 Correct 75 ms 208 KB Output is correct
51 Correct 59 ms 208 KB Output is correct
52 Correct 71 ms 208 KB Output is correct
53 Correct 98 ms 300 KB Output is correct
54 Correct 124 ms 356 KB Output is correct
55 Correct 120 ms 308 KB Output is correct
56 Correct 166 ms 388 KB Output is correct
57 Correct 197 ms 324 KB Output is correct
58 Correct 152 ms 504 KB Output is correct
59 Correct 187 ms 208 KB Output is correct
60 Correct 175 ms 336 KB Output is correct
61 Correct 159 ms 332 KB Output is correct
62 Correct 146 ms 316 KB Output is correct
63 Correct 141 ms 304 KB Output is correct
64 Correct 160 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 276 KB Output is correct
2 Correct 26 ms 208 KB Output is correct
3 Correct 53 ms 208 KB Output is correct
4 Partially correct 102 ms 208 KB Output is partially correct
5 Partially correct 159 ms 304 KB Output is partially correct
6 Correct 19 ms 208 KB Output is correct
7 Correct 36 ms 208 KB Output is correct
8 Correct 51 ms 208 KB Output is correct
9 Partially correct 88 ms 208 KB Output is partially correct
10 Partially correct 153 ms 336 KB Output is partially correct
11 Partially correct 137 ms 320 KB Output is partially correct
12 Partially correct 149 ms 328 KB Output is partially correct
13 Partially correct 148 ms 312 KB Output is partially correct
14 Correct 12 ms 208 KB Output is correct
15 Correct 11 ms 208 KB Output is correct
16 Correct 49 ms 208 KB Output is correct
17 Correct 47 ms 208 KB Output is correct
18 Correct 57 ms 208 KB Output is correct
19 Partially correct 96 ms 288 KB Output is partially correct
20 Partially correct 99 ms 208 KB Output is partially correct
21 Correct 15 ms 208 KB Output is correct
22 Correct 15 ms 236 KB Output is correct
23 Correct 30 ms 208 KB Output is correct
24 Correct 28 ms 208 KB Output is correct
25 Correct 33 ms 208 KB Output is correct
26 Partially correct 72 ms 208 KB Output is partially correct
27 Correct 49 ms 208 KB Output is correct
28 Correct 30 ms 208 KB Output is correct
29 Partially correct 78 ms 208 KB Output is partially correct
30 Partially correct 86 ms 208 KB Output is partially correct
31 Partially correct 61 ms 304 KB Output is partially correct
32 Correct 19 ms 208 KB Output is correct
33 Correct 17 ms 208 KB Output is correct
34 Correct 35 ms 208 KB Output is correct
35 Correct 35 ms 208 KB Output is correct
36 Correct 31 ms 208 KB Output is correct
37 Partially correct 64 ms 300 KB Output is partially correct
38 Partially correct 49 ms 208 KB Output is partially correct
39 Partially correct 77 ms 208 KB Output is partially correct
40 Partially correct 81 ms 308 KB Output is partially correct
41 Partially correct 98 ms 208 KB Output is partially correct
42 Partially correct 102 ms 308 KB Output is partially correct
43 Partially correct 141 ms 208 KB Output is partially correct
44 Partially correct 163 ms 316 KB Output is partially correct
45 Partially correct 147 ms 568 KB Output is partially correct
46 Partially correct 165 ms 324 KB Output is partially correct
47 Partially correct 157 ms 208 KB Output is partially correct
48 Partially correct 138 ms 312 KB Output is partially correct
49 Partially correct 142 ms 208 KB Output is partially correct
50 Partially correct 84 ms 308 KB Output is partially correct
51 Partially correct 59 ms 332 KB Output is partially correct
52 Partially correct 71 ms 332 KB Output is partially correct
53 Partially correct 79 ms 312 KB Output is partially correct
54 Partially correct 69 ms 316 KB Output is partially correct
55 Partially correct 72 ms 320 KB Output is partially correct
56 Partially correct 152 ms 316 KB Output is partially correct
57 Partially correct 102 ms 336 KB Output is partially correct
58 Partially correct 88 ms 316 KB Output is partially correct
59 Partially correct 62 ms 320 KB Output is partially correct
60 Partially correct 74 ms 324 KB Output is partially correct
61 Partially correct 61 ms 316 KB Output is partially correct
62 Partially correct 137 ms 324 KB Output is partially correct
63 Partially correct 178 ms 332 KB Output is partially correct
64 Partially correct 142 ms 360 KB Output is partially correct
65 Partially correct 161 ms 320 KB Output is partially correct
66 Partially correct 153 ms 316 KB Output is partially correct
67 Partially correct 158 ms 316 KB Output is partially correct
68 Partially correct 137 ms 320 KB Output is partially correct
69 Partially correct 140 ms 208 KB Output is partially correct
70 Partially correct 147 ms 336 KB Output is partially correct
71 Partially correct 162 ms 324 KB Output is partially correct
72 Partially correct 136 ms 320 KB Output is partially correct
73 Partially correct 155 ms 324 KB Output is partially correct
74 Partially correct 155 ms 468 KB Output is partially correct
75 Partially correct 178 ms 316 KB Output is partially correct
76 Partially correct 146 ms 544 KB Output is partially correct
77 Partially correct 152 ms 348 KB Output is partially correct
78 Partially correct 189 ms 208 KB Output is partially correct
79 Partially correct 148 ms 336 KB Output is partially correct
80 Partially correct 146 ms 308 KB Output is partially correct
81 Partially correct 151 ms 324 KB Output is partially correct
82 Partially correct 151 ms 316 KB Output is partially correct