Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <cassert>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
- #define REP(i, n) FOR (i, 0, n)
- #define _ << " _ " <<
- #define TRACE(x) cerr << #x << " = " << x << endl
- #define debug(...) fprintf(stderr, __VA_ARGS__)
- //#define debug
- //#define TRACE(x)
- using namespace std;
- typedef long long llint;
- const int MAX = 5005 * 3;
- int cnt[4];
- int poz;
- vector <int> R;
- int bio[MAX];
- int n;
- void go(int x) {
- assert(cnt[abs(x)]--);
- poz += x;
- TRACE(poz);
- assert(poz >= 0 && poz < n);
- assert(!bio[poz]++);
- R.push_back(poz);
- }
- void go_A() {
- go(3); go(-2); go(3); go(-2); go(3);
- }
- void go_B() {
- go(3); go(-2); go(1); go(2);
- }
- void fin_3_0() { //ima trojaka, nema dvojki
- assert(cnt[1] >= 2 && !cnt[2]);
- for (; cnt[1] > 2; ) go(1);
- int k = cnt[3] / 3;
- if (cnt[3] % 3 == 0) {
- REP(i, k) go(3);
- go(1);
- REP(i, k) go(-3);
- go(1);
- REP(i, k) go(3);
- }
- else if (cnt[3] % 3 == 1) {
- REP(i, k+1) go(3);
- go(-1);
- REP(i, k) go(-3);
- go(-1);
- REP(i, k) go(3);
- }
- else {
- REP(i, k+1) go(3);
- go(1);
- REP(i, k+1) go(-3);
- go(1);
- REP(i, k) go(3);
- }
- }
- void fin_3_1() { //ima trojaka, nema dvojaka
- assert(cnt[2] == 1 && cnt[1] > 0);
- for (; cnt[1] > 1; ) go(1);
- int k = cnt[3] / 3;
- if (cnt[3] % 3 == 0) {
- REP(i, k) go(3);
- go(2);
- REP(i, k) go(-3);
- go(1);
- REP(i, k) go(3);
- }
- }
- void fin_2() { //nema trojaka, ima dvojaka
- for (; cnt[1] > 1; ) go(1);
- int kol = (cnt[2]+1)/2, ost = cnt[2] % 2;
- REP(i, kol) go(2);
- if (ost) go(-1);
- else go(1);
- for (; cnt[2]; ) go(-2);
- }
- void print() {
- for (auto it : R)
- printf("%d ", it);
- printf("\n");
- }
- int main(void) {
- poz = 0;
- bio[0] = 1;
- R.push_back(0);
- cnt[1] = 3;
- cnt[2] = 1;
- cnt[3] = 6;
- n = cnt[1] + cnt[2] + cnt[3] + 1;
- fin_3_1();
- print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement