Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define debug(x) cout << #x << " = " << x << endl
  4. #define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
  5. #define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)
  6.  
  7. using namespace std;
  8.  
  9. typedef long long ll;
  10. typedef pair<int, int> ii;
  11.  
  12. inline void enter(int x) {
  13.     cout << "+" << x;
  14. }
  15.  
  16. inline void leave(int x) {
  17.     cout << "-" << x;
  18. }
  19.  
  20. inline void to_next(int x) {
  21.     cout << "++" << x;
  22. }
  23.  
  24. inline void to_prev(int x) {
  25.     cout << "--" << x;
  26. }
  27.  
  28. // type 0 -> from 000..000 to 100..000
  29. // type 1 -> from 100..000 to 000..000
  30. void roll(int left, int right, int type, int may_use) {
  31.     may_use = min(may_use, right - left + 1);
  32.     if(may_use == 1) {
  33.         if(type == 0) {
  34.             enter(right);
  35.             ford(i, right, left + 1) {
  36.                 to_prev(i);
  37.             }
  38.         }
  39.         else {
  40.             fori(i, left, right) {
  41.                 to_next(i);
  42.             }
  43.             leave(right);
  44.         }
  45.         return;
  46.     }
  47.     if(type == 0) {
  48.         roll(left + 1, right, 0, may_use);
  49.         enter(left);
  50.         roll(left + 1, right, 1, may_use - 1);
  51.     }
  52.     else {
  53.         roll(left + 1, right, 0, may_use - 1);
  54.         leave(left);
  55.         roll(left + 1, right, 1, may_use);
  56.     }
  57. }
  58.  
  59. int main() {
  60. #ifdef ONLINE_JUDGE
  61.     freopen("input.txt", "r", stdin);
  62.     freopen("output.txt", "w", stdout);
  63. #endif
  64.  
  65.     ios_base::sync_with_stdio(false);
  66.  
  67.     int n, k;
  68.     cin >> n >> k;
  69.     roll(1, n, 0, k);
  70.     leave(1);
  71.     cout << '\n';
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement