?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
188266618 |
Practice: DaiRuiChen007 |
1558C - 13 | C++14 (GCC 6-32) | Accepted | 15 ms | 96 KB | 2023-01-07 03:12:47 | 2023-01-07 03:12:48 |
// LUOGU_RID: 98877933 #include<bits/stdc++.h> using namespace std; const int MAXN=2022; int n,a[MAXN]; vector <int> ans; inline int find(int x) { for(int i=1;i<=n;++i) if(a[i]==x) return i; return 0; } inline void oper(int x) { ans.push_back(x); reverse(a+1,a+x+1); } inline void solve() { ans.clear(); scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); for(int i=1;i<=n;++i) { if(i%2!=a[i]%2) { puts("-1"); return ; } } for(int i=n;i>=3;i-=2) { int x=find(i); oper(x); int y=find(i-1); oper(y-1),oper(y+1),oper(3),oper(i); } printf("%d\n",(int)ans.size()); for(int i:ans) printf("%d ",i); puts(""); } signed main() { int T; scanf("%d",&T); while(T--) solve(); return 0; }
?
?
?
?