Submission #980177

# Submission time Handle Problem Language Result Execution time Memory
980177 2024-05-12T00:36:32 Z vjudge1 Longest Trip (IOI23_longesttrip) C++17
15 / 100
837 ms 2324 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using dll = deque <ll>;
using vi = vector <int>;

const ll MAXN = 256+16;
vll adj[MAXN];
bool mat[MAXN][MAXN];
ll comp[MAXN];

void dfs (ll u, ll col, ll &sz) {
    if (comp[u]) return;
    comp[u] = col;
    sz++;
    for (ll v : adj[u]) {
        dfs(v, col, sz);
    }
}

vi longest_trip (int n, int d) {
    fill(adj, adj+n, vll({}));
    fill(comp, comp+n+5, 0);
    for (ll u = 0; u < n; u++) {
        mat[u][u] = false;
        for (ll v = u+1; v < n; v++) {
            if (are_connected(vi({ int(u) }), vi({ int(v) }))) {
                adj[u].push_back(v);
                adj[v].push_back(u);
                mat[u][v] = true;
                mat[v][u] = true;
            } else {
                mat[u][v] = false;
                mat[v][u] = false;
            }
        }
    }
    ll c = 1;
    vll sz;
    for (ll u = 0; u < n; u++) {
        if (comp[u]) continue;
        sz.push_back(0);
        dfs(u, c++, sz.back());
    }
    if (c == 2) {
        dll dq;
        dq.push_back(0);
        vector <char> vis(n, false);
        vis[0] = true;
        for (ll v = 0; v < n; v++) {
            if (mat[0][v]) {
                vis[v] = true;
                dq.push_back(v);
                break;
            }
        }
        for (ll u = 0; u < n; u++) {
            if (vis[u]) continue;
            vis[u] = true;
            if (mat[u][dq.front()]) {
                dq.push_front(u);
            } else if (mat[u][dq.back()]) {
                dq.push_back(u);
            }
        }
        vi ans(dq.begin(), dq.end());
        return ans;
    } else if (c == 3) {
        ll maxC = max_element(sz.begin(), sz.end())-sz.begin() + 1;
        vi ans;
        for (ll u = 0; u < n; u++) {
            if (comp[u] == maxC) {
                ans.push_back(u);
            }
        }
        return ans;
    }
}

Compilation message

longesttrip.cpp: In function 'vi longest_trip(int, int)':
longesttrip.cpp:41:9: warning: control reaches end of non-void function [-Wreturn-type]
   41 |     vll sz;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 179 ms 1832 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Correct 127 ms 1128 KB Output is correct
4 Correct 372 ms 1412 KB Output is correct
5 Correct 769 ms 2212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 608 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 132 ms 856 KB Output is correct
4 Correct 322 ms 1368 KB Output is correct
5 Correct 739 ms 1920 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 26 ms 344 KB Output is correct
8 Correct 132 ms 1112 KB Output is correct
9 Correct 283 ms 1148 KB Output is correct
10 Correct 691 ms 1640 KB Output is correct
11 Correct 735 ms 1672 KB Output is correct
12 Correct 748 ms 1892 KB Output is correct
13 Correct 754 ms 2216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 344 KB Output is correct
2 Correct 20 ms 600 KB Output is correct
3 Correct 133 ms 856 KB Output is correct
4 Correct 343 ms 1520 KB Output is correct
5 Correct 765 ms 1880 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 128 ms 728 KB Output is correct
9 Correct 260 ms 856 KB Output is correct
10 Correct 722 ms 1984 KB Output is correct
11 Correct 695 ms 1644 KB Output is correct
12 Correct 758 ms 1652 KB Output is correct
13 Correct 773 ms 1160 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 41 ms 600 KB Output is correct
17 Correct 70 ms 856 KB Output is correct
18 Correct 124 ms 856 KB Output is correct
19 Correct 269 ms 1500 KB Output is correct
20 Correct 275 ms 1300 KB Output is correct
21 Correct 766 ms 2272 KB Output is correct
22 Correct 755 ms 2268 KB Output is correct
23 Correct 779 ms 2112 KB Output is correct
24 Correct 775 ms 1976 KB Output is correct
25 Correct 10 ms 500 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 24 ms 344 KB Output is correct
28 Correct 22 ms 344 KB Output is correct
29 Correct 26 ms 344 KB Output is correct
30 Correct 155 ms 1244 KB Output is correct
31 Correct 166 ms 996 KB Output is correct
32 Correct 161 ms 704 KB Output is correct
33 Correct 296 ms 1112 KB Output is correct
34 Correct 287 ms 884 KB Output is correct
35 Correct 292 ms 1384 KB Output is correct
36 Correct 793 ms 1652 KB Output is correct
37 Correct 785 ms 1716 KB Output is correct
38 Correct 723 ms 2024 KB Output is correct
39 Correct 746 ms 2028 KB Output is correct
40 Correct 771 ms 1992 KB Output is correct
41 Correct 767 ms 1596 KB Output is correct
42 Correct 837 ms 1356 KB Output is correct
43 Correct 795 ms 2176 KB Output is correct
44 Correct 758 ms 2276 KB Output is correct
45 Correct 11 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 24 ms 596 KB Output is correct
48 Correct 26 ms 340 KB Output is correct
49 Correct 21 ms 344 KB Output is correct
50 Correct 162 ms 732 KB Output is correct
51 Incorrect 13 ms 992 KB Incorrect
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Partially correct 122 ms 600 KB Output is partially correct
4 Partially correct 340 ms 1060 KB Output is partially correct
5 Partially correct 738 ms 1516 KB Output is partially correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Partially correct 134 ms 1112 KB Output is partially correct
9 Partially correct 267 ms 1396 KB Output is partially correct
10 Partially correct 761 ms 1860 KB Output is partially correct
11 Partially correct 745 ms 2324 KB Output is partially correct
12 Partially correct 733 ms 1560 KB Output is partially correct
13 Partially correct 774 ms 2080 KB Output is partially correct
14 Correct 8 ms 344 KB Output is correct
15 Incorrect 2 ms 344 KB Incorrect
16 Halted 0 ms 0 KB -