Submission #1103693

# Submission time Handle Problem Language Result Execution time Memory
1103693 2024-10-21T14:32:53 Z ortsac Political Development (BOI17_politicaldevelopment) C++17
77 / 100
3000 ms 94660 KB
#pragma GCC optmize("O3")
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define fr first
#define se second

const int MAXN = 5e4 + 10;

deque<int> oldAdj[MAXN];
deque<int> adj[MAXN]; 

void merge(deque<int>& v1, deque<int>& v2, deque<int>& res) {
    int n = v1.size(), m = v2.size();
    int p1 = 0, p2 = 0;
    while ((p1 < n) && (p2 < m)) {
        if (v1[p1] == v2[p2]) {
            res.push_back(v1[p1]);
            p1++;
            p2++;
            continue;
        }
        if (v1[p1] < v2[p2]) p1++;
        else p2++;
    }
}

int best(deque<int> pos) {
    int mx = 0;
    while (!pos.empty()) {
        auto u = pos.front();
        pos.pop_front();
        deque<int> nxt;
        merge(pos, adj[u], nxt);
        mx = max(mx, 1 + best(nxt));
    }
    return mx;
}

int32_t main() {
    int n, k;
    cin >> n >> k;
    vector<pii> ord;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ord.push_back({x, i});
        while (x--) {
            int v;
            cin >> v;
            oldAdj[i].push_back(v);
        }
        //sort(adj[i].begin(), adj[i].end());
    }
    vector<int> nname(n);
    sort(ord.begin(), ord.end());
    for (int i = 0; i < n; i++) nname[ord[i].se] = i;
    for (int i = 0; i < n; i++) {
        adj[nname[i]] = oldAdj[i];
        for (auto& u : adj[nname[i]]) u = nname[u];
        sort(adj[nname[i]].begin(), adj[nname[i]].end()); 
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, best(adj[i]) + 1);
    }
    cout << ans << "\n";
}

Compilation message

politicaldevelopment.cpp:1: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
    1 | #pragma GCC optmize("O3")
      |
# Verdict Execution time Memory Grader output
1 Correct 46 ms 67656 KB Output is correct
2 Correct 44 ms 67728 KB Output is correct
3 Correct 57 ms 70216 KB Output is correct
4 Correct 94 ms 70340 KB Output is correct
5 Correct 100 ms 70468 KB Output is correct
6 Correct 51 ms 70216 KB Output is correct
7 Correct 52 ms 70184 KB Output is correct
8 Correct 45 ms 67656 KB Output is correct
9 Correct 43 ms 67664 KB Output is correct
10 Correct 45 ms 67748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 67656 KB Output is correct
2 Correct 44 ms 67728 KB Output is correct
3 Correct 57 ms 70216 KB Output is correct
4 Correct 94 ms 70340 KB Output is correct
5 Correct 100 ms 70468 KB Output is correct
6 Correct 51 ms 70216 KB Output is correct
7 Correct 52 ms 70184 KB Output is correct
8 Correct 45 ms 67656 KB Output is correct
9 Correct 43 ms 67664 KB Output is correct
10 Correct 45 ms 67748 KB Output is correct
11 Correct 91 ms 70468 KB Output is correct
12 Correct 99 ms 70216 KB Output is correct
13 Correct 54 ms 67656 KB Output is correct
14 Correct 88 ms 70484 KB Output is correct
15 Correct 42 ms 67664 KB Output is correct
16 Correct 51 ms 70216 KB Output is correct
17 Correct 43 ms 67560 KB Output is correct
18 Correct 51 ms 70216 KB Output is correct
19 Correct 53 ms 67656 KB Output is correct
20 Correct 48 ms 70216 KB Output is correct
21 Correct 48 ms 70216 KB Output is correct
22 Correct 48 ms 67656 KB Output is correct
23 Correct 54 ms 70216 KB Output is correct
24 Correct 52 ms 67664 KB Output is correct
25 Correct 56 ms 70216 KB Output is correct
26 Correct 57 ms 70192 KB Output is correct
27 Correct 67 ms 70216 KB Output is correct
28 Correct 55 ms 70216 KB Output is correct
29 Correct 55 ms 70216 KB Output is correct
30 Correct 60 ms 70272 KB Output is correct
31 Correct 51 ms 70356 KB Output is correct
32 Correct 65 ms 70216 KB Output is correct
33 Correct 60 ms 70188 KB Output is correct
34 Correct 58 ms 70292 KB Output is correct
35 Correct 58 ms 68860 KB Output is correct
36 Correct 55 ms 68948 KB Output is correct
37 Correct 57 ms 68936 KB Output is correct
38 Correct 50 ms 68168 KB Output is correct
39 Correct 52 ms 68424 KB Output is correct
40 Correct 67 ms 70384 KB Output is correct
41 Correct 54 ms 68424 KB Output is correct
42 Correct 57 ms 70380 KB Output is correct
43 Correct 58 ms 70348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 67664 KB Output is correct
2 Correct 49 ms 67656 KB Output is correct
3 Correct 50 ms 67652 KB Output is correct
4 Correct 50 ms 67676 KB Output is correct
5 Correct 48 ms 67656 KB Output is correct
6 Correct 46 ms 67656 KB Output is correct
7 Correct 61 ms 67656 KB Output is correct
8 Correct 48 ms 67756 KB Output is correct
9 Correct 46 ms 67656 KB Output is correct
10 Correct 52 ms 67656 KB Output is correct
11 Correct 271 ms 94148 KB Output is correct
12 Correct 62 ms 67656 KB Output is correct
13 Correct 262 ms 94144 KB Output is correct
14 Correct 47 ms 67656 KB Output is correct
15 Correct 274 ms 94148 KB Output is correct
16 Correct 262 ms 94148 KB Output is correct
17 Correct 261 ms 94148 KB Output is correct
18 Correct 268 ms 94148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 67656 KB Output is correct
2 Correct 44 ms 67728 KB Output is correct
3 Correct 57 ms 70216 KB Output is correct
4 Correct 94 ms 70340 KB Output is correct
5 Correct 100 ms 70468 KB Output is correct
6 Correct 51 ms 70216 KB Output is correct
7 Correct 52 ms 70184 KB Output is correct
8 Correct 45 ms 67656 KB Output is correct
9 Correct 43 ms 67664 KB Output is correct
10 Correct 45 ms 67748 KB Output is correct
11 Correct 91 ms 70468 KB Output is correct
12 Correct 99 ms 70216 KB Output is correct
13 Correct 54 ms 67656 KB Output is correct
14 Correct 88 ms 70484 KB Output is correct
15 Correct 42 ms 67664 KB Output is correct
16 Correct 51 ms 70216 KB Output is correct
17 Correct 43 ms 67560 KB Output is correct
18 Correct 51 ms 70216 KB Output is correct
19 Correct 53 ms 67656 KB Output is correct
20 Correct 48 ms 70216 KB Output is correct
21 Correct 48 ms 70216 KB Output is correct
22 Correct 48 ms 67656 KB Output is correct
23 Correct 54 ms 70216 KB Output is correct
24 Correct 52 ms 67664 KB Output is correct
25 Correct 56 ms 70216 KB Output is correct
26 Correct 57 ms 70192 KB Output is correct
27 Correct 67 ms 70216 KB Output is correct
28 Correct 55 ms 70216 KB Output is correct
29 Correct 55 ms 70216 KB Output is correct
30 Correct 60 ms 70272 KB Output is correct
31 Correct 51 ms 70356 KB Output is correct
32 Correct 65 ms 70216 KB Output is correct
33 Correct 60 ms 70188 KB Output is correct
34 Correct 58 ms 70292 KB Output is correct
35 Correct 58 ms 68860 KB Output is correct
36 Correct 55 ms 68948 KB Output is correct
37 Correct 57 ms 68936 KB Output is correct
38 Correct 50 ms 68168 KB Output is correct
39 Correct 52 ms 68424 KB Output is correct
40 Correct 67 ms 70384 KB Output is correct
41 Correct 54 ms 68424 KB Output is correct
42 Correct 57 ms 70380 KB Output is correct
43 Correct 58 ms 70348 KB Output is correct
44 Correct 184 ms 70216 KB Output is correct
45 Correct 47 ms 67656 KB Output is correct
46 Correct 58 ms 70160 KB Output is correct
47 Correct 58 ms 70228 KB Output is correct
48 Correct 54 ms 70216 KB Output is correct
49 Correct 59 ms 70352 KB Output is correct
50 Correct 60 ms 70216 KB Output is correct
51 Correct 79 ms 70216 KB Output is correct
52 Correct 90 ms 70652 KB Output is correct
53 Correct 1366 ms 70728 KB Output is correct
54 Correct 102 ms 70216 KB Output is correct
55 Correct 52 ms 70216 KB Output is correct
56 Correct 98 ms 70292 KB Output is correct
57 Correct 45 ms 67656 KB Output is correct
58 Correct 1384 ms 70776 KB Output is correct
59 Correct 60 ms 70220 KB Output is correct
60 Correct 57 ms 70216 KB Output is correct
61 Correct 69 ms 70216 KB Output is correct
62 Correct 65 ms 70312 KB Output is correct
63 Correct 198 ms 70216 KB Output is correct
64 Correct 119 ms 70472 KB Output is correct
65 Correct 60 ms 70236 KB Output is correct
66 Correct 62 ms 70224 KB Output is correct
67 Correct 103 ms 70220 KB Output is correct
68 Correct 118 ms 70220 KB Output is correct
69 Correct 67 ms 70216 KB Output is correct
70 Correct 71 ms 70224 KB Output is correct
71 Correct 103 ms 70216 KB Output is correct
72 Correct 87 ms 70228 KB Output is correct
73 Correct 55 ms 70316 KB Output is correct
74 Correct 68 ms 70212 KB Output is correct
75 Correct 84 ms 70228 KB Output is correct
76 Correct 69 ms 70232 KB Output is correct
77 Correct 74 ms 70172 KB Output is correct
78 Correct 56 ms 70216 KB Output is correct
79 Correct 63 ms 68840 KB Output is correct
80 Correct 70 ms 70212 KB Output is correct
81 Correct 77 ms 70216 KB Output is correct
82 Correct 59 ms 68436 KB Output is correct
83 Correct 60 ms 68936 KB Output is correct
84 Correct 65 ms 70232 KB Output is correct
85 Correct 55 ms 68192 KB Output is correct
86 Correct 68 ms 70216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 67656 KB Output is correct
2 Correct 44 ms 67728 KB Output is correct
3 Correct 57 ms 70216 KB Output is correct
4 Correct 94 ms 70340 KB Output is correct
5 Correct 100 ms 70468 KB Output is correct
6 Correct 51 ms 70216 KB Output is correct
7 Correct 52 ms 70184 KB Output is correct
8 Correct 45 ms 67656 KB Output is correct
9 Correct 43 ms 67664 KB Output is correct
10 Correct 45 ms 67748 KB Output is correct
11 Correct 91 ms 70468 KB Output is correct
12 Correct 99 ms 70216 KB Output is correct
13 Correct 54 ms 67656 KB Output is correct
14 Correct 88 ms 70484 KB Output is correct
15 Correct 42 ms 67664 KB Output is correct
16 Correct 51 ms 70216 KB Output is correct
17 Correct 43 ms 67560 KB Output is correct
18 Correct 51 ms 70216 KB Output is correct
19 Correct 53 ms 67656 KB Output is correct
20 Correct 48 ms 70216 KB Output is correct
21 Correct 48 ms 70216 KB Output is correct
22 Correct 48 ms 67656 KB Output is correct
23 Correct 54 ms 70216 KB Output is correct
24 Correct 52 ms 67664 KB Output is correct
25 Correct 56 ms 70216 KB Output is correct
26 Correct 57 ms 70192 KB Output is correct
27 Correct 67 ms 70216 KB Output is correct
28 Correct 55 ms 70216 KB Output is correct
29 Correct 55 ms 70216 KB Output is correct
30 Correct 60 ms 70272 KB Output is correct
31 Correct 51 ms 70356 KB Output is correct
32 Correct 65 ms 70216 KB Output is correct
33 Correct 60 ms 70188 KB Output is correct
34 Correct 58 ms 70292 KB Output is correct
35 Correct 58 ms 68860 KB Output is correct
36 Correct 55 ms 68948 KB Output is correct
37 Correct 57 ms 68936 KB Output is correct
38 Correct 50 ms 68168 KB Output is correct
39 Correct 52 ms 68424 KB Output is correct
40 Correct 67 ms 70384 KB Output is correct
41 Correct 54 ms 68424 KB Output is correct
42 Correct 57 ms 70380 KB Output is correct
43 Correct 58 ms 70348 KB Output is correct
44 Correct 49 ms 67656 KB Output is correct
45 Correct 214 ms 94404 KB Output is correct
46 Correct 1225 ms 94400 KB Output is correct
47 Correct 207 ms 94148 KB Output is correct
48 Correct 185 ms 94148 KB Output is correct
49 Execution timed out 3079 ms 94660 KB Time limit exceeded
50 Halted 0 ms 0 KB -