Submission #1079647

# Submission time Handle Problem Language Result Execution time Memory
1079647 2024-08-28T19:44:42 Z c2zi6 Longest Trip (IOI23_longesttrip) C++17
85 / 100
18 ms 692 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "longesttrip.h"

int n;

VI rev(VI a) {
    reverse(all(a));
    return a;
}

// int are_connected(VI a, VI b);

VI longest_trip(int N, int D) {
    n = N;
    VI path1;
    VI path2;

    VI order;
    rep(i, n) order.pb(i);
    mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
    shuffle(all(order), rng);

    path1.pb(order[0]);
    path2.pb(order[1]);
    replr(i, 2, n-1) {
        int u = order[i];
        if (are_connected({path1.back()}, {u})) path1.pb(u);
        else if (are_connected({path2.back()}, {u})) path2.pb(u);
        else {
            for (int u : rev(path2)) path1.pb(u);
            path2 = VI{u};
        }
    }

    if (are_connected({path2[0]}, {path1[0]})) {
        VI ans;
        for (int x : rev(path2)) ans.pb(x);
        for (int x : path1) ans.pb(x);
        return ans;
    }
    if (are_connected({path2.back()}, {path1[0]})) {
        VI ans;
        for (int x : path2) ans.pb(x);
        for (int x : path1) ans.pb(x);
        return ans;
    }
    if (are_connected({path1.back()}, {path2[0]})) {
        VI ans;
        for (int x : path1) ans.pb(x);
        for (int x : path2) ans.pb(x);
        return ans;
    }

    auto getind2 = [&](int ind1){
        auto ardyoq = [&](int x) {
            VI tmp;
            rep(i, x+1) tmp.pb(path2[i]);
            return are_connected({path1[ind1]}, tmp);
        };
        int l = -1, r = path2.size();
        while (l + 1 < r) {
            int m = (l + r) / 2;
            if (ardyoq(m)) r = m;
            else l = m;
        }
        if (r == path2.size()) return -1;
        return r;
    };
    auto getind1 = [&]() {
        auto ardyoq = [&](int x) {
            VI a, b;
            rep(i, x+1) a.pb(path1[i]);
            rep(i, path2.size()) b.pb(path2[i]);
            return are_connected(a, b);
        };
        int l = -1, r = path1.size();
        while (l + 1 < r) {
            int m = (l + r) / 2;
            if (ardyoq(m)) r = m;
            else l = m;
        }
        if (r == path1.size()) return -1;
        return r;
    };

    int ind1 = getind1();
    if (ind1 == -1) {
        if (path1.size() > path2.size()) return path1;
        return path2;
    }
    int ind2 = getind2(ind1);

    VI ans;
    replr(i, ind2+1, ind2+1 + path2.size()-1) {
        ans.pb(path2[i%(int)path2.size()]);
    }
    replr(i, ind1, ind1 + path1.size()-1) {
        ans.pb(path1[i%(int)path1.size()]);
    }
    return ans;
}




Compilation message

longesttrip.cpp: In lambda function:
longesttrip.cpp:96:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |         if (r == path2.size()) return -1;
      |             ~~^~~~~~~~~~~~~~~
longesttrip.cpp: In lambda function:
longesttrip.cpp:112:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         if (r == path1.size()) return -1;
      |             ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 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 5 ms 596 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 13 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 6 ms 416 KB Output is correct
21 Correct 9 ms 344 KB Output is correct
22 Correct 7 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 8 ms 344 KB Output is correct
25 Correct 12 ms 344 KB Output is correct
26 Correct 13 ms 344 KB Output is correct
27 Correct 10 ms 344 KB Output is correct
28 Correct 18 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 7 ms 600 KB Output is correct
31 Correct 8 ms 344 KB Output is correct
32 Correct 11 ms 344 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 6 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 6 ms 344 KB Output is correct
38 Correct 7 ms 344 KB Output is correct
39 Correct 12 ms 344 KB Output is correct
40 Correct 9 ms 344 KB Output is correct
41 Correct 8 ms 344 KB Output is correct
42 Correct 9 ms 344 KB Output is correct
43 Correct 8 ms 344 KB Output is correct
44 Correct 6 ms 444 KB Output is correct
45 Correct 12 ms 344 KB Output is correct
46 Correct 10 ms 344 KB Output is correct
47 Correct 11 ms 344 KB Output is correct
48 Correct 8 ms 344 KB Output is correct
49 Correct 10 ms 344 KB Output is correct
50 Correct 8 ms 344 KB Output is correct
51 Correct 11 ms 344 KB Output is correct
52 Correct 6 ms 344 KB Output is correct
53 Correct 7 ms 344 KB Output is correct
54 Correct 9 ms 344 KB Output is correct
55 Correct 8 ms 344 KB Output is correct
56 Correct 6 ms 344 KB Output is correct
57 Correct 6 ms 344 KB Output is correct
58 Correct 7 ms 344 KB Output is correct
59 Correct 8 ms 600 KB Output is correct
60 Correct 8 ms 448 KB Output is correct
61 Correct 8 ms 344 KB Output is correct
62 Correct 6 ms 344 KB Output is correct
63 Correct 7 ms 344 KB Output is correct
64 Correct 9 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 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 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 6 ms 436 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 14 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 7 ms 344 KB Output is correct
17 Correct 6 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 16 ms 344 KB Output is correct
22 Correct 12 ms 344 KB Output is correct
23 Correct 10 ms 344 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 9 ms 344 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 6 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 7 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 9 ms 344 KB Output is correct
36 Correct 8 ms 344 KB Output is correct
37 Correct 7 ms 344 KB Output is correct
38 Correct 11 ms 436 KB Output is correct
39 Correct 6 ms 344 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 7 ms 344 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 7 ms 344 KB Output is correct
45 Correct 6 ms 340 KB Output is correct
46 Correct 7 ms 344 KB Output is correct
47 Correct 7 ms 344 KB Output is correct
48 Correct 7 ms 344 KB Output is correct
49 Partially correct 8 ms 340 KB Output is partially correct
50 Correct 6 ms 344 KB Output is correct
51 Partially correct 6 ms 344 KB Output is partially correct
52 Correct 10 ms 440 KB Output is correct
53 Correct 9 ms 440 KB Output is correct
54 Correct 8 ms 448 KB Output is correct
55 Correct 8 ms 344 KB Output is correct
56 Partially correct 5 ms 344 KB Output is partially correct
57 Correct 6 ms 344 KB Output is correct
58 Partially correct 8 ms 440 KB Output is partially correct
59 Partially correct 8 ms 344 KB Output is partially correct
60 Correct 6 ms 344 KB Output is correct
61 Correct 8 ms 344 KB Output is correct
62 Correct 5 ms 344 KB Output is correct
63 Correct 5 ms 344 KB Output is correct
64 Correct 7 ms 344 KB Output is correct
65 Partially correct 9 ms 344 KB Output is partially correct
66 Partially correct 7 ms 344 KB Output is partially correct
67 Correct 10 ms 344 KB Output is correct
68 Correct 7 ms 344 KB Output is correct
69 Partially correct 6 ms 596 KB Output is partially correct
70 Partially correct 8 ms 344 KB Output is partially correct
71 Correct 7 ms 344 KB Output is correct
72 Partially correct 6 ms 344 KB Output is partially correct
73 Partially correct 7 ms 344 KB Output is partially correct
74 Correct 14 ms 692 KB Output is correct
75 Correct 7 ms 344 KB Output is correct
76 Correct 9 ms 344 KB Output is correct
77 Correct 6 ms 448 KB Output is correct
78 Partially correct 8 ms 444 KB Output is partially correct
79 Partially correct 5 ms 344 KB Output is partially correct
80 Partially correct 8 ms 344 KB Output is partially correct
81 Correct 8 ms 344 KB Output is correct
82 Correct 10 ms 344 KB Output is correct