fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define vi vector<int>
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define ii pair<int , int>
  9. #define pq priority_queue
  10. #define iii pair<int , pair<int , int>>
  11. #define fo(i,l,r) for(int i=l;i<=r;i++)
  12. #define fod(i,r,l) for(int i=r;i>=l;i--)
  13. #define fill(f,x) memset(f,x,sizeof(f))
  14. #define NAME "file"
  15.  
  16. const int N = 2e5 + 5, mod = 1e9 + 7;
  17. int n , k , a[21] , b[21] , p[21] , cnt = 0;
  18.  
  19. void sol(int i)
  20. {
  21. if (i > n)
  22. {
  23. stack <int> st;
  24. for (int j = 1 ; j <= n ; j++)
  25. {
  26. if (p[j] == 0)
  27. {
  28. st.push(0);
  29. }
  30. else
  31. {
  32. if (st.empty()) return;
  33. st.pop();
  34. }
  35. }
  36. if (st.empty()) cnt++;
  37. if (cnt == k)
  38. {
  39. for (int j = 1 ; j <= n ; j++)
  40. {
  41. if (p[j] == 0) cout << '(';
  42. else cout << ')';
  43. }
  44. exit(0);
  45. }
  46. }
  47. else
  48. {
  49. for (int j = 0 ; j <= 1 ; j++)
  50. {
  51. p[i] = j;
  52. sol(i + 1);
  53. }
  54. }
  55. }
  56.  
  57. signed main()
  58. {
  59. ios_base::sync_with_stdio(0);
  60. cin.tie(0); cout.tie(0);
  61. //freopen(NAME".INP" , "r" , stdin);
  62. //freopen(NAME".OUT" , "w" , stdout);
  63.  
  64. cin >> n >> k;
  65. sol(1);
  66. cout << -1;
  67. }
  68. // haronnee_
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
-1