Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- inline void enter(int i) {
- cout << "+" << i;
- }
- inline void leave(int i) {
- cout << "-" << i;
- }
- inline void next(int i) {
- cout << "++" << i;
- }
- inline void prev(int i) {
- cout << "--" << i;
- }
- void A(int L, int R, int Y);
- void B(int L, int R, int Y);
- void A(int L, int R, int Y) {
- Y = min(Y, R - L + 1);
- if(Y == 1) {
- enter(R);
- for(int i = R; i > L; i--) {
- prev(i);
- }
- }
- else {
- A(L + 1, R, Y);
- enter(L);
- B(L + 1, R, Y - 1);
- }
- }
- void B(int L, int R, int Y) {
- Y = min(Y, R - L + 1);
- if(Y == 1) {
- for(int i = L; i < R; i++) {
- next(i);
- }
- leave(R);
- }
- else {
- A(L + 1, R, Y - 1);
- leave(L);
- B(L + 1, R, Y);
- }
- }
- int main() {
- #ifdef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, k;
- cin >> n >> k;
- A(1, n, k);
- leave(1);
- cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement