Codeforces Round 867 (Div. 3) 1822D - Super-Permutation Solution


  

Problem Link : https://codeforces.com/contest/1822/problem/D

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ;
  11. cin >> n ;
  12. if ( n == 1 ) {
  13. cout <<"1"<<endl;
  14. continue ;
  15. }
  16. else if ( n % 2 ) {
  17. cout <<"-1" <<endl;
  18. }
  19. else {
  20. int j = 1 ;
  21. for ( int i = n ; i > 0 ; i-- ) {
  22. if ( i % 2 ) {
  23. cout << j <<" ";
  24. j+=2;
  25. }
  26. else
  27. cout << i <<" " ;
  28. }
  29. cout << endl;
  30. }
  31. }
  32. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.