Codeforces Round 867 (Div. 3) 1822D - Super-Permutation Solution
Problem Link : https://codeforces.com/contest/1822/problem/D
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- if ( n == 1 ) {
- cout <<"1"<<endl;
- continue ;
- }
- else if ( n % 2 ) {
- cout <<"-1" <<endl;
- }
- else {
- int j = 1 ;
- for ( int i = n ; i > 0 ; i-- ) {
- if ( i % 2 ) {
- cout << j <<" ";
- j+=2;
- }
- else
- cout << i <<" " ;
- }
- cout << endl;
- }
- }
- }
No comments