| #include <bits/stdc++.h> |
| using namespace std; |
|
|
| vector<int> get_ds(long long t) { |
| if (t == 0) return {}; |
| if (t < 0 || t % 2 != 0) return {-1}; |
| |
| vector<int> res_two; |
| if (t >= 6 && (t - 6) % 2 == 0) { |
| long long sub = (t - 6) / 2; |
| auto sub_ds = get_ds(sub); |
| bool success = sub_ds.empty() || (!sub_ds.empty() && sub_ds[0] != -1); |
| if (success) { |
| res_two = {2}; |
| res_two.insert(res_two.end(), sub_ds.begin(), sub_ds.end()); |
| return res_two; |
| } |
| } |
| |
| long long sub = t - 2; |
| if (sub < 0) return {-1}; |
| auto sub_ds = get_ds(sub); |
| bool success = sub_ds.empty() || (!sub_ds.empty() && sub_ds[0] != -1); |
| if (!success) return {-1}; |
| vector<int> res = {1}; |
| res.insert(res.end(), sub_ds.begin(), sub_ds.end()); |
| return res; |
| } |
|
|
| int next_pos_global; |
| vector<string> pprog_global; |
| int n_global; |
| int halt_pos_global; |
|
|
| void build_level(int lev, int after_pos, const vector<int>& ds) { |
| int m = ds.size(); |
| int dd = ds[m - 1 - lev]; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int dd = levels[lev]; |
| bool has_inner = (lev > 0); |
| int l_start = next_pos_global++; |
| int disp; |
| if (dd == 1) { |
| int p1 = next_pos_global++; |
| disp = p1; |
| if (has_inner) { |
| int inner_start_temp = next_pos_global; |
| build_level(lev - 1, disp, levels); |
| int this_inner_start = inner_start_temp; |
| pprog_global[l_start - 1] = "POP 100 GOTO " + to_string(after_pos) + " PUSH 1 GOTO " + to_string(this_inner_start); |
| pprog_global[p1 - 1] = "POP 1 GOTO " + to_string(after_pos) + " PUSH 1024 GOTO " + to_string(after_pos); |
| } else { |
| int this_inner_start = p1; |
| pprog_global[l_start - 1] = "POP 100 GOTO " + to_string(after_pos) + " PUSH 1 GOTO " + to_string(this_inner_start); |
| pprog_global[p1 - 1] = "POP 1 GOTO " + to_string(after_pos) + " PUSH 1024 GOTO " + to_string(after_pos); |
| } |
| } else { |
| int push1p = next_pos_global++; |
| int d_disp = next_pos_global++; |
| int p3 = next_pos_global++; |
| int p1 = next_pos_global++; |
| disp = d_disp; |
| int temp_inner = 0; |
| if (has_inner) { |
| int inner_start_temp = next_pos_global; |
| build_level(lev - 1, disp, levels); |
| temp_inner = inner_start_temp; |
| } else { |
| temp_inner = d_disp; |
| } |
| pprog_global[l_start - 1] = "POP 100 GOTO " + to_string(after_pos) + " PUSH 2 GOTO " + to_string(temp_inner); |
| pprog_global[push1p - |