Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define debug(x) cout << #x << " = " << x << endl
- #define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
- #define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> ii;
- inline void enter(int x) {
- cout << "+" << x;
- }
- inline void leave(int x) {
- cout << "-" << x;
- }
- inline void to_next(int x) {
- cout << "++" << x;
- }
- inline void to_prev(int x) {
- cout << "--" << x;
- }
- // type 0 -> from 000..000 to 100..000
- // type 1 -> from 100..000 to 000..000
- void roll(int left, int right, int type, int may_use) {
- may_use = min(may_use, right - left + 1);
- if(may_use == 1) {
- if(type == 0) {
- enter(right);
- ford(i, right, left + 1) {
- to_prev(i);
- }
- }
- else {
- fori(i, left, right) {
- to_next(i);
- }
- leave(right);
- }
- return;
- }
- if(type == 0) {
- roll(left + 1, right, 0, may_use);
- enter(left);
- roll(left + 1, right, 1, may_use - 1);
- }
- else {
- roll(left + 1, right, 0, may_use - 1);
- leave(left);
- roll(left + 1, right, 1, may_use);
- }
- }
- int main() {
- #ifdef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- int n, k;
- cin >> n >> k;
- roll(1, n, 0, k);
- leave(1);
- cout << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement