10709 | 2024-04-10 09:44:25 | szil | Szimmetrikus sorozat | cpp17 | Accepted 100/100 | 145ms | 37584 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 200'001;
int a[MAXN], mine;
bool vis[MAXN];
vector<int> c;
vector<int> g[MAXN];
vector<pair<int, int>> ans;
void dfs(int u) {
vis[u] = true;
mine = min(mine, u);
c.emplace_back(u);
for (int v : g[u]) {
if (!vis[v]) {
dfs(v);
}
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<int> comp;
for (int i = 1; i <= n; i++) {
cin >> a[i];
comp.emplace_back(a[i]);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i = 1; i <= n; i++) a[i] = lower_bound(comp.begin(), comp.end(), a[i])-comp.begin();
for (int i = 1; i <= n; i++) {
if (a[i] != a[n-i+1]) {
g[a[i]].emplace_back(a[n-i+1]);
}
}
for (int i = 0; i < comp.size(); i++) {
if (!vis[i]) {
mine = 1e9;
dfs(i);
for (int j : c) {
if (j != mine) {
ans.emplace_back(comp[j], comp[mine]);
}
}
c.clear();
}
}
cout << ans.size() << "\n";
for (auto [a, b] : ans) cout << a << " " << b << "\n";
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 6ms | 11260 KiB | ||||
2 | Accepted | 64ms | 19156 KiB | ||||
subtask2 | 9/9 | ||||||
3 | Accepted | 7ms | 11840 KiB | ||||
4 | Accepted | 7ms | 12172 KiB | ||||
5 | Accepted | 7ms | 12248 KiB | ||||
6 | Accepted | 7ms | 12596 KiB | ||||
7 | Accepted | 7ms | 12560 KiB | ||||
subtask3 | 14/14 | ||||||
8 | Accepted | 7ms | 12400 KiB | ||||
9 | Accepted | 7ms | 12400 KiB | ||||
10 | Accepted | 7ms | 12656 KiB | ||||
11 | Accepted | 6ms | 12876 KiB | ||||
12 | Accepted | 7ms | 12824 KiB | ||||
13 | Accepted | 7ms | 13080 KiB | ||||
subtask4 | 25/25 | ||||||
14 | Accepted | 6ms | 13176 KiB | ||||
15 | Accepted | 7ms | 13456 KiB | ||||
16 | Accepted | 8ms | 13584 KiB | ||||
17 | Accepted | 8ms | 13788 KiB | ||||
18 | Accepted | 8ms | 13756 KiB | ||||
19 | Accepted | 8ms | 13740 KiB | ||||
20 | Accepted | 7ms | 14000 KiB | ||||
21 | Accepted | 7ms | 14164 KiB | ||||
subtask5 | 22/22 | ||||||
22 | Accepted | 90ms | 25352 KiB | ||||
23 | Accepted | 107ms | 37584 KiB | ||||
24 | Accepted | 104ms | 37476 KiB | ||||
25 | Accepted | 93ms | 25460 KiB | ||||
26 | Accepted | 90ms | 25436 KiB | ||||
27 | Accepted | 105ms | 36436 KiB | ||||
28 | Accepted | 107ms | 36440 KiB | ||||
29 | Accepted | 92ms | 25444 KiB | ||||
30 | Accepted | 89ms | 25436 KiB | ||||
31 | Accepted | 104ms | 37028 KiB | ||||
32 | Accepted | 101ms | 37020 KiB | ||||
33 | Accepted | 90ms | 25432 KiB | ||||
34 | Accepted | 86ms | 25452 KiB | ||||
35 | Accepted | 100ms | 31368 KiB | ||||
36 | Accepted | 103ms | 34604 KiB | ||||
37 | Accepted | 90ms | 25640 KiB | ||||
subtask6 | 30/30 | ||||||
38 | Accepted | 6ms | 14264 KiB | ||||
39 | Accepted | 64ms | 22152 KiB | ||||
40 | Accepted | 7ms | 11840 KiB | ||||
41 | Accepted | 7ms | 12172 KiB | ||||
42 | Accepted | 7ms | 12248 KiB | ||||
43 | Accepted | 7ms | 12596 KiB | ||||
44 | Accepted | 7ms | 12560 KiB | ||||
45 | Accepted | 7ms | 12400 KiB | ||||
46 | Accepted | 7ms | 12400 KiB | ||||
47 | Accepted | 7ms | 12656 KiB | ||||
48 | Accepted | 6ms | 12876 KiB | ||||
49 | Accepted | 7ms | 12824 KiB | ||||
50 | Accepted | 7ms | 13080 KiB | ||||
51 | Accepted | 6ms | 13176 KiB | ||||
52 | Accepted | 7ms | 13456 KiB | ||||
53 | Accepted | 8ms | 13584 KiB | ||||
54 | Accepted | 8ms | 13788 KiB | ||||
55 | Accepted | 8ms | 13756 KiB | ||||
56 | Accepted | 8ms | 13740 KiB | ||||
57 | Accepted | 7ms | 14000 KiB | ||||
58 | Accepted | 7ms | 14164 KiB | ||||
59 | Accepted | 90ms | 25352 KiB | ||||
60 | Accepted | 107ms | 37584 KiB | ||||
61 | Accepted | 104ms | 37476 KiB | ||||
62 | Accepted | 93ms | 25460 KiB | ||||
63 | Accepted | 90ms | 25436 KiB | ||||
64 | Accepted | 105ms | 36436 KiB | ||||
65 | Accepted | 107ms | 36440 KiB | ||||
66 | Accepted | 92ms | 25444 KiB | ||||
67 | Accepted | 89ms | 25436 KiB | ||||
68 | Accepted | 104ms | 37028 KiB | ||||
69 | Accepted | 101ms | 37020 KiB | ||||
70 | Accepted | 90ms | 25432 KiB | ||||
71 | Accepted | 86ms | 25452 KiB | ||||
72 | Accepted | 100ms | 31368 KiB | ||||
73 | Accepted | 103ms | 34604 KiB | ||||
74 | Accepted | 90ms | 25640 KiB | ||||
75 | Accepted | 136ms | 28840 KiB | ||||
76 | Accepted | 111ms | 25900 KiB | ||||
77 | Accepted | 52ms | 19768 KiB | ||||
78 | Accepted | 112ms | 25924 KiB | ||||
79 | Accepted | 86ms | 22224 KiB | ||||
80 | Accepted | 82ms | 18036 KiB | ||||
81 | Accepted | 82ms | 18044 KiB | ||||
82 | Accepted | 82ms | 18044 KiB | ||||
83 | Accepted | 145ms | 28840 KiB | ||||
84 | Accepted | 59ms | 19784 KiB | ||||
85 | Accepted | 90ms | 22232 KiB | ||||
86 | Accepted | 90ms | 18044 KiB | ||||
87 | Accepted | 90ms | 18048 KiB | ||||
88 | Accepted | 90ms | 18036 KiB | ||||
89 | Accepted | 87ms | 18044 KiB |