답안 #1080656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080656 2024-08-29T11:56:42 Z shmax 가장 긴 여행 (IOI23_longesttrip) C++17
40 / 100
680 ms 856 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 {
        int ct = 0;
        int border = n * 1200;
        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));
                ct += len(t) + 1;
                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;
                    ct += len(get_part(tm)) + 1;
                    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 = 15;
        vec<int> best;
        while (T--) {
            if (ct > border) break;
            auto g = attempt();
            if (len(g) > len(best))
                best = g;
            if (len(best) == n) break;
        }
        return best;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 14 ms 716 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 5 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 6 ms 484 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 8 ms 344 KB Output is correct
11 Correct 8 ms 344 KB Output is correct
12 Correct 7 ms 356 KB Output is correct
13 Correct 9 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 18 ms 344 KB Output is correct
3 Correct 44 ms 344 KB Output is correct
4 Correct 61 ms 600 KB Output is correct
5 Correct 68 ms 344 KB Output is correct
6 Correct 9 ms 344 KB Output is correct
7 Correct 15 ms 344 KB Output is correct
8 Correct 41 ms 344 KB Output is correct
9 Correct 45 ms 344 KB Output is correct
10 Correct 84 ms 600 KB Output is correct
11 Correct 66 ms 724 KB Output is correct
12 Correct 53 ms 344 KB Output is correct
13 Correct 73 ms 480 KB Output is correct
14 Correct 117 ms 344 KB Output is correct
15 Correct 122 ms 344 KB Output is correct
16 Correct 25 ms 344 KB Output is correct
17 Correct 36 ms 344 KB Output is correct
18 Correct 32 ms 444 KB Output is correct
19 Correct 42 ms 344 KB Output is correct
20 Correct 46 ms 452 KB Output is correct
21 Correct 73 ms 480 KB Output is correct
22 Correct 55 ms 344 KB Output is correct
23 Correct 70 ms 344 KB Output is correct
24 Correct 80 ms 344 KB Output is correct
25 Correct 135 ms 344 KB Output is correct
26 Correct 133 ms 344 KB Output is correct
27 Correct 307 ms 344 KB Output is correct
28 Correct 306 ms 344 KB Output is correct
29 Correct 276 ms 344 KB Output is correct
30 Correct 680 ms 344 KB Output is correct
31 Correct 460 ms 344 KB Output is correct
32 Correct 385 ms 344 KB Output is correct
33 Correct 639 ms 344 KB Output is correct
34 Correct 640 ms 344 KB Output is correct
35 Correct 610 ms 344 KB Output is correct
36 Correct 347 ms 344 KB Output is correct
37 Correct 413 ms 600 KB Output is correct
38 Correct 341 ms 344 KB Output is correct
39 Correct 341 ms 344 KB Output is correct
40 Correct 272 ms 600 KB Output is correct
41 Correct 243 ms 344 KB Output is correct
42 Correct 258 ms 344 KB Output is correct
43 Correct 264 ms 344 KB Output is correct
44 Correct 245 ms 484 KB Output is correct
45 Correct 11 ms 344 KB Output is correct
46 Correct 13 ms 344 KB Output is correct
47 Correct 49 ms 344 KB Output is correct
48 Correct 37 ms 344 KB Output is correct
49 Correct 37 ms 344 KB Output is correct
50 Correct 343 ms 344 KB Output is correct
51 Correct 199 ms 344 KB Output is correct
52 Correct 161 ms 344 KB Output is correct
53 Correct 544 ms 344 KB Output is correct
54 Correct 383 ms 344 KB Output is correct
55 Correct 399 ms 344 KB Output is correct
56 Correct 327 ms 344 KB Output is correct
57 Correct 350 ms 608 KB Output is correct
58 Correct 187 ms 600 KB Output is correct
59 Correct 303 ms 344 KB Output is correct
60 Correct 308 ms 600 KB Output is correct
61 Correct 175 ms 344 KB Output is correct
62 Correct 231 ms 600 KB Output is correct
63 Correct 266 ms 728 KB Output is correct
64 Correct 179 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 16 ms 344 KB Output is correct
3 Correct 35 ms 344 KB Output is correct
4 Partially correct 45 ms 344 KB Output is partially correct
5 Partially correct 73 ms 600 KB Output is partially correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 16 ms 344 KB Output is correct
8 Correct 36 ms 344 KB Output is correct
9 Partially correct 41 ms 344 KB Output is partially correct
10 Partially correct 67 ms 856 KB Output is partially correct
11 Partially correct 70 ms 600 KB Output is partially correct
12 Partially correct 67 ms 596 KB Output is partially correct
13 Partially correct 79 ms 600 KB Output is partially correct
14 Correct 100 ms 344 KB Output is correct
15 Correct 112 ms 344 KB Output is correct
16 Correct 22 ms 344 KB Output is correct
17 Correct 35 ms 344 KB Output is correct
18 Correct 29 ms 600 KB Output is correct
19 Partially correct 58 ms 344 KB Output is partially correct
20 Partially correct 44 ms 456 KB Output is partially correct
21 Correct 128 ms 592 KB Output is correct
22 Correct 129 ms 596 KB Output is correct
23 Partially correct 302 ms 344 KB Output is partially correct
24 Partially correct 270 ms 596 KB Output is partially correct
25 Partially correct 294 ms 344 KB Output is partially correct
26 Partially correct 659 ms 344 KB Output is partially correct
27 Partially correct 506 ms 344 KB Output is partially correct
28 Partially correct 402 ms 344 KB Output is partially correct
29 Partially correct 626 ms 344 KB Output is partially correct
30 Partially correct 619 ms 344 KB Output is partially correct
31 Partially correct 596 ms 344 KB Output is partially correct
32 Correct 12 ms 344 KB Output is correct
33 Correct 10 ms 344 KB Output is correct
34 Correct 47 ms 344 KB Output is correct
35 Correct 45 ms 344 KB Output is correct
36 Correct 31 ms 344 KB Output is correct
37 Incorrect 53 ms 344 KB Incorrect
38 Halted 0 ms 0 KB -