10925 | 2024-04-19 12:20:02 | k_balint | Szimmetrikus sorozat | cpp17 | Accepted 100/100 | 177ms | 41092 KiB |
#include <bits/stdc++.h>
using namespace std;
const int c=2e5+5;
int n;
int arr[c];
vector<int> adj[c];
vector<int> comp;
bool vis[c];
vector<pair<int,int>> ans;
void dfs(int v, int val){
vis[v]=1;
for(int x:adj[v]){
if(!vis[x]){
ans.push_back(make_pair(comp[x], val));
dfs(x, val);
}
}
}
int f(int k){
return lower_bound(comp.begin(),comp.end(),k)-comp.begin();
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
comp.push_back(0);
for(int i=1;i<=n;i++){
cin>>arr[i];
comp.push_back(arr[i]);
}
sort(comp.begin(), comp.end());
comp.resize(unique(comp.begin(),comp.end())-comp.begin());
for(int i=1;i<=n;i++){
int a = n-i+1;
if(arr[i]==arr[a]) continue;
adj[f(arr[i])].push_back(f(arr[a]));
}
for(int i=1;i<comp.size();i++){
if(!vis[i]) dfs(i,comp[i]);
}
cout << ans.size() << '\n';
for(pair<int,int> x:ans){
cout << x.first << ' ' << x.second << '\n';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 6ms | 11328 KiB | ||||
2 | Accepted | 76ms | 19088 KiB | ||||
subtask2 | 9/9 | ||||||
3 | Accepted | 6ms | 11908 KiB | ||||
4 | Accepted | 7ms | 12232 KiB | ||||
5 | Accepted | 7ms | 12572 KiB | ||||
6 | Accepted | 7ms | 12784 KiB | ||||
7 | Accepted | 7ms | 12788 KiB | ||||
subtask3 | 14/14 | ||||||
8 | Accepted | 7ms | 12924 KiB | ||||
9 | Accepted | 7ms | 12936 KiB | ||||
10 | Accepted | 6ms | 13296 KiB | ||||
11 | Accepted | 7ms | 13292 KiB | ||||
12 | Accepted | 6ms | 13188 KiB | ||||
13 | Accepted | 7ms | 13468 KiB | ||||
subtask4 | 25/25 | ||||||
14 | Accepted | 6ms | 13544 KiB | ||||
15 | Accepted | 6ms | 13592 KiB | ||||
16 | Accepted | 8ms | 14080 KiB | ||||
17 | Accepted | 8ms | 13996 KiB | ||||
18 | Accepted | 8ms | 14104 KiB | ||||
19 | Accepted | 8ms | 13844 KiB | ||||
20 | Accepted | 8ms | 13840 KiB | ||||
21 | Accepted | 7ms | 13788 KiB | ||||
subtask5 | 22/22 | ||||||
22 | Accepted | 104ms | 25248 KiB | ||||
23 | Accepted | 115ms | 40912 KiB | ||||
24 | Accepted | 115ms | 40952 KiB | ||||
25 | Accepted | 108ms | 25480 KiB | ||||
26 | Accepted | 104ms | 25488 KiB | ||||
27 | Accepted | 119ms | 39328 KiB | ||||
28 | Accepted | 115ms | 39676 KiB | ||||
29 | Accepted | 104ms | 25664 KiB | ||||
30 | Accepted | 103ms | 25648 KiB | ||||
31 | Accepted | 119ms | 40904 KiB | ||||
32 | Accepted | 115ms | 41092 KiB | ||||
33 | Accepted | 105ms | 25712 KiB | ||||
34 | Accepted | 101ms | 25728 KiB | ||||
35 | Accepted | 111ms | 32616 KiB | ||||
36 | Accepted | 108ms | 36768 KiB | ||||
37 | Accepted | 97ms | 25704 KiB | ||||
subtask6 | 30/30 | ||||||
38 | Accepted | 7ms | 14584 KiB | ||||
39 | Accepted | 76ms | 22108 KiB | ||||
40 | Accepted | 6ms | 11908 KiB | ||||
41 | Accepted | 7ms | 12232 KiB | ||||
42 | Accepted | 7ms | 12572 KiB | ||||
43 | Accepted | 7ms | 12784 KiB | ||||
44 | Accepted | 7ms | 12788 KiB | ||||
45 | Accepted | 7ms | 12924 KiB | ||||
46 | Accepted | 7ms | 12936 KiB | ||||
47 | Accepted | 6ms | 13296 KiB | ||||
48 | Accepted | 7ms | 13292 KiB | ||||
49 | Accepted | 6ms | 13188 KiB | ||||
50 | Accepted | 7ms | 13468 KiB | ||||
51 | Accepted | 6ms | 13544 KiB | ||||
52 | Accepted | 6ms | 13592 KiB | ||||
53 | Accepted | 8ms | 14080 KiB | ||||
54 | Accepted | 8ms | 13996 KiB | ||||
55 | Accepted | 8ms | 14104 KiB | ||||
56 | Accepted | 8ms | 13844 KiB | ||||
57 | Accepted | 8ms | 13840 KiB | ||||
58 | Accepted | 7ms | 13788 KiB | ||||
59 | Accepted | 104ms | 25248 KiB | ||||
60 | Accepted | 115ms | 40912 KiB | ||||
61 | Accepted | 115ms | 40952 KiB | ||||
62 | Accepted | 108ms | 25480 KiB | ||||
63 | Accepted | 104ms | 25488 KiB | ||||
64 | Accepted | 119ms | 39328 KiB | ||||
65 | Accepted | 115ms | 39676 KiB | ||||
66 | Accepted | 104ms | 25664 KiB | ||||
67 | Accepted | 103ms | 25648 KiB | ||||
68 | Accepted | 119ms | 40904 KiB | ||||
69 | Accepted | 115ms | 41092 KiB | ||||
70 | Accepted | 105ms | 25712 KiB | ||||
71 | Accepted | 101ms | 25728 KiB | ||||
72 | Accepted | 111ms | 32616 KiB | ||||
73 | Accepted | 108ms | 36768 KiB | ||||
74 | Accepted | 97ms | 25704 KiB | ||||
75 | Accepted | 172ms | 28904 KiB | ||||
76 | Accepted | 137ms | 26924 KiB | ||||
77 | Accepted | 59ms | 19784 KiB | ||||
78 | Accepted | 137ms | 27000 KiB | ||||
79 | Accepted | 111ms | 22464 KiB | ||||
80 | Accepted | 52ms | 18104 KiB | ||||
81 | Accepted | 52ms | 18104 KiB | ||||
82 | Accepted | 52ms | 18108 KiB | ||||
83 | Accepted | 177ms | 28904 KiB | ||||
84 | Accepted | 64ms | 19868 KiB | ||||
85 | Accepted | 115ms | 22464 KiB | ||||
86 | Accepted | 57ms | 18108 KiB | ||||
87 | Accepted | 57ms | 18100 KiB | ||||
88 | Accepted | 57ms | 18216 KiB | ||||
89 | Accepted | 57ms | 18320 KiB |