# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
315100 |
2020-10-22T02:30:59 Z |
Seanliu |
Cat (info1cup19_cat) |
C++14 |
|
0 ms |
0 KB |
#include <iostream>
#include <vector>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
using namespace std;
const int maxN = 3e6 + 326;
int N, arr[maxN], pos[maxN], T, posc, ansc;
pii ans[maxN];
bool vis[maxN];
inline void makeMove(int i, int j){
swap(arr[i], arr[j]);
swap(arr[N - i + 1], arr[N - j + 1]);
}
inline void disp(){
for(int i = 1; i <= N; i++) cout << arr[i] << " \n"[i == N];
}
inline void solve(){
cin >> N;
for(int i = 1; i <= N; i++) cin >> arr[i];
for(int i = 1; i <= N / 2; i++) if(arr[i] + arr[N - i + 1] != N + 1){
cout << -1 << endl;
return;
}
posc = ansc = 0;
for(int i = 1; i <= N / 2; i++) if(arr[i] > arr[N - i + 1]) pos[posc++] = i;
if(posc & 1){ //not sure about this
cout << -1 << endl;
return;
}
/*
cout << "have: ";
for(int x : pos) cout << x << " ";
cout << endl;
*/
for(int i = 0; i < (int)pos.size(); i += 2){
makeMove(pos[i], N - pos[i + 1] + 1);
ans[ansc++] = {pos[i], N - pos[i + 1] + 1};
}
//disp();
fill(vis, vis + N + 1, false);
for(int i = 1; i <= N / 2; i++){
while(i != arr[i]){
int nxt = arr[i];
makeMove(i, arr[i]);
ans[anc++] = {i, nxt};
//disp();
}
}
cout << ansc << " " << ansc << endl;
for(int i = 0; i < ansc; i++) cout << ans[i].F << " " << ans[i].S << endl;
}
int main(){
//ericxiao
cin >> T;
while(T--){
solve();
}
}
Compilation message
cat.cpp: In function 'void solve()':
cat.cpp:44:30: error: request for member 'size' in 'pos', which is of non-class type 'int [3000326]'
44 | for(int i = 0; i < (int)pos.size(); i += 2){
| ^~~~
cat.cpp:54:8: error: 'anc' was not declared in this scope; did you mean 'ans'?
54 | ans[anc++] = {i, nxt};
| ^~~
| ans