Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. inline void enter(int i) {
  6.     cout << "+" << i;
  7. }
  8.  
  9. inline void leave(int i) {
  10.     cout << "-" << i;
  11. }
  12.  
  13. inline void next(int i) {
  14.     cout << "++" << i;
  15. }
  16.  
  17. inline void prev(int i) {
  18.     cout << "--" << i;
  19. }
  20.  
  21. void A(int L, int R, int Y);
  22. void B(int L, int R, int Y);
  23.  
  24. void A(int L, int R, int Y) {
  25.     Y = min(Y, R - L + 1);
  26.     if(Y == 1) {
  27.         enter(R);
  28.         for(int i = R; i > L; i--) {
  29.             prev(i);
  30.         }
  31.     }
  32.     else {
  33.         A(L + 1, R, Y);
  34.         enter(L);
  35.         B(L + 1, R, Y - 1);
  36.     }
  37. }
  38.  
  39. void B(int L, int R, int Y) {
  40.     Y = min(Y, R - L + 1);
  41.     if(Y == 1) {
  42.         for(int i = L; i < R; i++) {
  43.             next(i);
  44.         }
  45.         leave(R);
  46.     }
  47.     else {
  48.         A(L + 1, R, Y - 1);
  49.         leave(L);
  50.         B(L + 1, R, Y);
  51.     }
  52. }
  53.  
  54. int main() {
  55. #ifdef ONLINE_JUDGE
  56.     freopen("input.txt", "r", stdin);
  57.     freopen("output.txt", "w", stdout);
  58. #endif
  59.  
  60.     int n, k;
  61.     cin >> n >> k;
  62.     A(1, n, k);
  63.     leave(1);
  64.     cout << '\n';
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement