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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.