# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
861275 |
2023-10-15T19:03:55 Z |
Ahmed57 |
Cat (info1cup19_cat) |
C++17 |
|
1000 ms |
7496 KB |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> con;
int vis[200001],arr[200001];
void dfs(int i,int st){
if(st!=i)con.push_back({st,i});
vis[i] = 1;
if(vis[arr[i]]==0)dfs(arr[i],st);
}
int main(){
int t;cin>>t;
z:while(t--){
int n;cin>>n;
for(int i = 1;i<=n;i++)vis[i] = 0;
con.clear();
int pos[n+1];
for(int i = 1;i<=n;i++){
cin>>arr[i];pos[arr[i]] = i;
}
int g = 0;int lol = 0;
for(int i = 1;i<=n/2;i++){
if(arr[i]!=i)g++;
if(n-arr[i]+1!=arr[n-i+1]){
cout<<-1<<endl;
goto z;
}if(arr[i]>n/2){
lol++;
}
}
if(lol&1){
cout<<-1<<endl;
goto z;
}
for(int i = 1;i<=n/2;i++){
if(!vis[i])dfs(i,i);
}
cout<<con.size()<<" "<<con.size()<<endl;
for(auto i:con)cout<<i.first<<" "<<i.second<<endl;
}
}
Compilation message
cat.cpp: In function 'int main()':
cat.cpp:17:13: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
17 | int pos[n+1];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
344 KB |
Correctly distinguished between possibility and impossibility |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
596 KB |
Output is correct |
2 |
Correct |
73 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
344 KB |
Correctly distinguished between possibility and impossibility |
2 |
Correct |
75 ms |
596 KB |
Output is correct |
3 |
Correct |
73 ms |
512 KB |
Output is correct |
4 |
Correct |
140 ms |
916 KB |
Correctly distinguished between possibility and impossibility |
5 |
Correct |
46 ms |
596 KB |
Correctly distinguished between possibility and impossibility |
6 |
Correct |
38 ms |
348 KB |
Correctly distinguished between possibility and impossibility |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
596 KB |
Output is correct |
2 |
Correct |
73 ms |
512 KB |
Output is correct |
3 |
Execution timed out |
1061 ms |
7496 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
344 KB |
Correctly distinguished between possibility and impossibility |
2 |
Correct |
75 ms |
596 KB |
Output is correct |
3 |
Correct |
73 ms |
512 KB |
Output is correct |
4 |
Correct |
140 ms |
916 KB |
Correctly distinguished between possibility and impossibility |
5 |
Correct |
46 ms |
596 KB |
Correctly distinguished between possibility and impossibility |
6 |
Correct |
38 ms |
348 KB |
Correctly distinguished between possibility and impossibility |
7 |
Execution timed out |
1061 ms |
7496 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |