fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pb push_back
  5. #define fi first
  6. #define se second
  7. #define mp make_pair
  8. #define endl '\n';
  9. #define sz(x) ((int)(x).size())
  10. #define min(a, b) a < b ? a : b
  11. #define all(x) (x).begin(), (x).end()
  12. #define rall(x) (x).rbegin(), (x).rend()
  13. #define show(x) cout << #x << " = " << x << endl
  14. #define yes cout << "YES\n"
  15. #define no cout << "NO\n"
  16. void dbg_out()
  17. {
  18. cerr << endl;
  19. }
  20. template <typename Head, typename... Tail>
  21. void dbg_out(Head H, Tail... T)
  22. {
  23. cerr << ' ' << H;
  24. dbg_out(T...);
  25. }
  26. #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
  27. typedef long long ll;
  28. // const int N = 2e5 + 5;
  29. const int MOD = (1e9) + 7;
  30.  
  31.  
  32. void solve() {
  33. int N;
  34. cin >> N;
  35. int size = 2*N;
  36. vector<int> slots(size, 0);
  37. bool possible = true;
  38. for(int i = N; i >=1; --i){
  39. bool placed = false;
  40. for(int p =0; p +i < size; ++p){
  41. if(slots[p]==0 && slots[p+i]==0){
  42. slots[p] = i;
  43. slots[p+i] = i;
  44. placed = true;
  45. break;
  46. }
  47. }
  48. if(!placed){
  49. possible = false;
  50. break;
  51. }
  52. }
  53. if(possible){
  54. string output;
  55. for(int idx =0; idx < size; ++idx){
  56. output += to_string(slots[idx]);
  57. if(idx != size-1){
  58. output += ' ';
  59. }
  60. }
  61. cout << output << '\n';
  62. }
  63. else{
  64. cout << "-1\n";
  65. }
  66. }
  67.  
  68.  
  69.  
  70. int main()
  71. {
  72. // freopen("input.txt", "r", stdin);
  73. ios::sync_with_stdio(0);
  74. cin.tie(0);
  75. cout.tie(0);
  76. int T = 1;
  77. cin >> T;
  78. while (T--)
  79. {
  80. solve();
  81. }
  82.  
  83. return 0;
  84. }
  85.  
Success #stdin #stdout 0.01s 5280KB
stdin
2
13
12
stdout
13 11 12 8 5 10 2 9 2 5 7 8 11 13 12 10 9 7 6 4 1 1 3 4 6 3
12 10 11 7 5 9 2 8 2 5 7 10 12 11 9 8 6 4 1 1 3 4 6 3