10827 | 2024-04-16 08:24:08 | TomaSajt | Szimmetrikus sorozat | cpp17 | Accepted 100/100 | 194ms | 34320 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int>> g;
vector<int> color, parent, depth;
int get_root(int u) {
if (u == parent[u]) return u;
return parent[u] = get_root(parent[u]);
}
vector<array<int, 2>> sol;
void merge(int u, int v, bool init) {
u = get_root(u), v = get_root(v);
if (u == v) return;
if (!init) assert(color[u] != color[v]);
if (depth[u] < depth[v]) swap(u, v);
if (depth[u] == depth[v]) depth[u]++;
int c1 = min(color[u], color[v]);
int c2 = max(color[u], color[v]);
color[u] = c1;
parent[v] = u;
if (init) return;
sol.push_back({c2, c1});
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
parent.resize(n + 1);
iota(parent.begin(), parent.end(), 0);
depth.assign(n + 1, 1);
color.resize(n + 1);
map<int, int> col_map;
for (int i = 1; i <= n; i++) {
cin >> color[i];
if (col_map.count(color[i])) {
merge(col_map[color[i]], i, true);
}
else {
col_map[color[i]] = i;
}
}
for (int i = 1; i <= n; i++) {
int j = n - i + 1;
if (j <= i) break;
merge(i, j, false);
}
cout << sol.size() << endl;
for (auto [a, b] : sol) cout << a << ' ' << b << '\n';
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1700 KiB | ||||
2 | Accepted | 75ms | 14608 KiB | ||||
subtask2 | 9/9 | ||||||
3 | Accepted | 3ms | 2396 KiB | ||||
4 | Accepted | 3ms | 2492 KiB | ||||
5 | Accepted | 3ms | 2768 KiB | ||||
6 | Accepted | 3ms | 2652 KiB | ||||
7 | Accepted | 3ms | 2940 KiB | ||||
subtask3 | 14/14 | ||||||
8 | Accepted | 3ms | 2924 KiB | ||||
9 | Accepted | 2ms | 3004 KiB | ||||
10 | Accepted | 3ms | 3132 KiB | ||||
11 | Accepted | 3ms | 3368 KiB | ||||
12 | Accepted | 3ms | 3572 KiB | ||||
13 | Accepted | 3ms | 3660 KiB | ||||
subtask4 | 25/25 | ||||||
14 | Accepted | 3ms | 3660 KiB | ||||
15 | Accepted | 3ms | 3988 KiB | ||||
16 | Accepted | 4ms | 4436 KiB | ||||
17 | Accepted | 4ms | 4692 KiB | ||||
18 | Accepted | 4ms | 4472 KiB | ||||
19 | Accepted | 4ms | 4616 KiB | ||||
20 | Accepted | 4ms | 4568 KiB | ||||
21 | Accepted | 4ms | 4648 KiB | ||||
subtask5 | 22/22 | ||||||
22 | Accepted | 123ms | 28324 KiB | ||||
23 | Accepted | 129ms | 30376 KiB | ||||
24 | Accepted | 134ms | 30320 KiB | ||||
25 | Accepted | 119ms | 28252 KiB | ||||
26 | Accepted | 122ms | 28292 KiB | ||||
27 | Accepted | 125ms | 30476 KiB | ||||
28 | Accepted | 128ms | 30556 KiB | ||||
29 | Accepted | 115ms | 28488 KiB | ||||
30 | Accepted | 103ms | 28656 KiB | ||||
31 | Accepted | 109ms | 30744 KiB | ||||
32 | Accepted | 114ms | 30752 KiB | ||||
33 | Accepted | 97ms | 28704 KiB | ||||
34 | Accepted | 83ms | 28704 KiB | ||||
35 | Accepted | 98ms | 30904 KiB | ||||
36 | Accepted | 100ms | 30900 KiB | ||||
37 | Accepted | 86ms | 28696 KiB | ||||
subtask6 | 30/30 | ||||||
38 | Accepted | 3ms | 4824 KiB | ||||
39 | Accepted | 82ms | 17568 KiB | ||||
40 | Accepted | 3ms | 2396 KiB | ||||
41 | Accepted | 3ms | 2492 KiB | ||||
42 | Accepted | 3ms | 2768 KiB | ||||
43 | Accepted | 3ms | 2652 KiB | ||||
44 | Accepted | 3ms | 2940 KiB | ||||
45 | Accepted | 3ms | 2924 KiB | ||||
46 | Accepted | 2ms | 3004 KiB | ||||
47 | Accepted | 3ms | 3132 KiB | ||||
48 | Accepted | 3ms | 3368 KiB | ||||
49 | Accepted | 3ms | 3572 KiB | ||||
50 | Accepted | 3ms | 3660 KiB | ||||
51 | Accepted | 3ms | 3660 KiB | ||||
52 | Accepted | 3ms | 3988 KiB | ||||
53 | Accepted | 4ms | 4436 KiB | ||||
54 | Accepted | 4ms | 4692 KiB | ||||
55 | Accepted | 4ms | 4472 KiB | ||||
56 | Accepted | 4ms | 4616 KiB | ||||
57 | Accepted | 4ms | 4568 KiB | ||||
58 | Accepted | 4ms | 4648 KiB | ||||
59 | Accepted | 123ms | 28324 KiB | ||||
60 | Accepted | 129ms | 30376 KiB | ||||
61 | Accepted | 134ms | 30320 KiB | ||||
62 | Accepted | 119ms | 28252 KiB | ||||
63 | Accepted | 122ms | 28292 KiB | ||||
64 | Accepted | 125ms | 30476 KiB | ||||
65 | Accepted | 128ms | 30556 KiB | ||||
66 | Accepted | 115ms | 28488 KiB | ||||
67 | Accepted | 103ms | 28656 KiB | ||||
68 | Accepted | 109ms | 30744 KiB | ||||
69 | Accepted | 114ms | 30752 KiB | ||||
70 | Accepted | 97ms | 28704 KiB | ||||
71 | Accepted | 83ms | 28704 KiB | ||||
72 | Accepted | 98ms | 30904 KiB | ||||
73 | Accepted | 100ms | 30900 KiB | ||||
74 | Accepted | 86ms | 28696 KiB | ||||
75 | Accepted | 192ms | 34068 KiB | ||||
76 | Accepted | 144ms | 22648 KiB | ||||
77 | Accepted | 57ms | 17056 KiB | ||||
78 | Accepted | 137ms | 22600 KiB | ||||
79 | Accepted | 101ms | 17576 KiB | ||||
80 | Accepted | 131ms | 26284 KiB | ||||
81 | Accepted | 133ms | 26132 KiB | ||||
82 | Accepted | 142ms | 26188 KiB | ||||
83 | Accepted | 194ms | 34320 KiB | ||||
84 | Accepted | 63ms | 17120 KiB | ||||
85 | Accepted | 111ms | 17588 KiB | ||||
86 | Accepted | 144ms | 26668 KiB | ||||
87 | Accepted | 144ms | 26664 KiB | ||||
88 | Accepted | 143ms | 26792 KiB | ||||
89 | Accepted | 140ms | 26792 KiB |