답안 #1080630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080630 2024-08-29T11:43:57 Z shmax 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
424 ms 748 KB
#include "longesttrip.h"
#include "bits/stdc++.h"

using namespace std;
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define inf 1000'000'000'000'000'000LL
#define bit(x, i) (((x) >> i) & 1)


template<typename T>
using vec = vector<T>;

std::vector<int> longest_trip(int n, int d) {
    mt19937 rnd(14345);
    if (d == 3) {
        vec<int> ans(n);
        iota(all(ans), 0);
        return ans;
    }
    if (d == 2) {
        deque<int> ans;
        int cur = 0;
        ans.push_back(cur);
        set<int> not_used;
        for (int i = 1; i < n; i++) {
            not_used.insert(i);
        }
        while (true) {
            if (not_used.empty()) break;
            vec<int> next(all(not_used));
            int nxt = next[0];
            if (are_connected({cur}, {nxt})) {
                ans.push_back(nxt);
                not_used.erase(nxt);
                cur = nxt;
            } else {
                if (next.size() == 1) {
                    ans.push_front(next[0]);
                    break;
                } else {
                    int net = next[1];
                    ans.push_back(net);
                    not_used.erase(net);
                    cur = net;
                }
            }
        }
        return vec<int>(all(ans));
    } else {

        auto attempt = [&]() {
            deque<int> ans;
            int cur = rnd() % n;
            ans.push_back(cur);
            set<int> not_used;
            for (int i = 0; i < n; i++) {
                if (i != cur) not_used.insert(i);
            }
            auto try_find = [&](int v) {
                vec<int> t(all(not_used));
                if (!are_connected({v}, t)) return -1;
                shuffle(all(t), rnd);
                int tl = 0;
                int tr = len(t) - 1;
                auto get_part = [&](int f) {
                    vec<int> r;
                    for (int i = 0; i <= f; i++)
                        r.push_back(t[i]);
                    return r;
                };
                while (tl != tr) {
                    int tm = (tl + tr) / 2;
                    if (are_connected({v}, get_part(tm))) {
                        tr = tm;
                    } else {
                        tl = tm + 1;
                    }
                }
                return  t[tl];
            };

            while (true) {
                if (not_used.empty()) break;
                int u = try_find(ans.back());
                if (u == -1) break;
                ans.push_back(u);
                not_used.erase(u);
            }
            while (true) {
                if (not_used.empty()) break;
                int u = try_find(ans.front());
                if (u == -1) break;
                ans.push_front(u);
                not_used.erase(u);
            }
            return vec<int>(all(ans));
        };
        int T = 5;
        vec<int> best;
        while (T--) {
            auto g = attempt();
            if (len(g) > len(best))
                best = g;
        }
        return best;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 88 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 7 ms 344 KB Output is correct
11 Correct 10 ms 344 KB Output is correct
12 Correct 6 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 344 KB Output is correct
2 Correct 101 ms 596 KB Output is correct
3 Correct 199 ms 344 KB Output is correct
4 Correct 287 ms 344 KB Output is correct
5 Correct 366 ms 604 KB Output is correct
6 Correct 27 ms 344 KB Output is correct
7 Correct 96 ms 344 KB Output is correct
8 Correct 227 ms 420 KB Output is correct
9 Correct 262 ms 600 KB Output is correct
10 Correct 424 ms 596 KB Output is correct
11 Correct 392 ms 344 KB Output is correct
12 Correct 364 ms 344 KB Output is correct
13 Correct 318 ms 728 KB Output is correct
14 Correct 43 ms 344 KB Output is correct
15 Correct 44 ms 344 KB Output is correct
16 Correct 91 ms 344 KB Output is correct
17 Correct 157 ms 344 KB Output is correct
18 Correct 237 ms 344 KB Output is correct
19 Correct 249 ms 344 KB Output is correct
20 Correct 212 ms 344 KB Output is correct
21 Correct 326 ms 496 KB Output is correct
22 Correct 344 ms 504 KB Output is correct
23 Correct 339 ms 508 KB Output is correct
24 Correct 412 ms 472 KB Output is correct
25 Correct 52 ms 344 KB Output is correct
26 Correct 42 ms 344 KB Output is correct
27 Correct 99 ms 344 KB Output is correct
28 Correct 86 ms 344 KB Output is correct
29 Correct 85 ms 344 KB Output is correct
30 Correct 213 ms 344 KB Output is correct
31 Correct 177 ms 344 KB Output is correct
32 Correct 117 ms 344 KB Output is correct
33 Correct 278 ms 344 KB Output is correct
34 Correct 238 ms 600 KB Output is correct
35 Correct 248 ms 344 KB Output is correct
36 Correct 391 ms 740 KB Output is correct
37 Correct 332 ms 712 KB Output is correct
38 Correct 330 ms 748 KB Output is correct
39 Correct 199 ms 344 KB Output is correct
40 Correct 241 ms 600 KB Output is correct
41 Correct 232 ms 620 KB Output is correct
42 Correct 207 ms 344 KB Output is correct
43 Correct 219 ms 476 KB Output is correct
44 Correct 214 ms 480 KB Output is correct
45 Correct 50 ms 344 KB Output is correct
46 Correct 46 ms 344 KB Output is correct
47 Correct 105 ms 344 KB Output is correct
48 Correct 110 ms 344 KB Output is correct
49 Correct 80 ms 344 KB Output is correct
50 Correct 235 ms 344 KB Output is correct
51 Correct 180 ms 344 KB Output is correct
52 Correct 135 ms 344 KB Output is correct
53 Correct 253 ms 344 KB Output is correct
54 Correct 271 ms 344 KB Output is correct
55 Correct 250 ms 344 KB Output is correct
56 Correct 350 ms 600 KB Output is correct
57 Correct 326 ms 344 KB Output is correct
58 Correct 279 ms 496 KB Output is correct
59 Correct 229 ms 344 KB Output is correct
60 Correct 215 ms 472 KB Output is correct
61 Correct 238 ms 480 KB Output is correct
62 Correct 206 ms 480 KB Output is correct
63 Correct 205 ms 492 KB Output is correct
64 Correct 231 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 344 KB Output is correct
2 Correct 91 ms 344 KB Output is correct
3 Partially correct 191 ms 344 KB Output is partially correct
4 Partially correct 283 ms 600 KB Output is partially correct
5 Partially correct 334 ms 344 KB Output is partially correct
6 Correct 29 ms 344 KB Output is correct
7 Correct 95 ms 344 KB Output is correct
8 Partially correct 201 ms 424 KB Output is partially correct
9 Partially correct 236 ms 600 KB Output is partially correct
10 Partially correct 380 ms 600 KB Output is partially correct
11 Partially correct 356 ms 592 KB Output is partially correct
12 Partially correct 365 ms 344 KB Output is partially correct
13 Partially correct 348 ms 344 KB Output is partially correct
14 Correct 33 ms 344 KB Output is correct
15 Incorrect 4 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -