Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Franciszek Witt
- //NIENAWIDZE CF-LIKE CONSTRUCTIVE ZADAN
- #include<bits/stdc++.h>
- using namespace std;
- #define FOR(i,l,r) for(int i=(l);i<=(r);++i)
- #define REP(i,n) FOR(i,0,(n)-1)
- #define ssize(x) int(x.size())
- template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
- template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
- #ifdef DEBUG
- #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
- #else
- #define debug(...) {}
- #endif
- typedef long long ll;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- auto tos = [&] (int x) {
- assert(1 <= x && x <= 9);
- return string("") + char(x + '0');
- };
- function<string(const string, ll)> rp = [&] (const string s, ll n) {
- if(n == 0 || ssize(s) == 0)
- return string("");
- if(n == 1)
- return s;
- if(n < 10)
- return tos(n) + "[" + s + "]";
- if(n % 9 == 0)
- return "9[" + rp(s, n / 9) + "]";
- return rp(s, n % 9) + rp(s, n - (n % 9));
- };
- const string RI = "A", RD = "B", LD = "C", LE = "D", LU = "E", RU = "F";
- auto trap = [&] (ll n) {
- if(n == 0)
- return string("");
- return rp(rp(LD + LU, n - 1) + LD + rp(RI, n), n) + rp(LU, n);
- };
- //jezeli ramka to wracamy w to samo miejsce
- //jak bez ramki to przechodzimy krawedzia z ramka
- function<string(ll, bool)> solver = [&] (ll n, bool ramka) {
- debug(n, ramka);
- if(n == 0)
- return string("");
- if(n == 1) {
- string ret = RU;
- if(ramka)
- ret += RD + LE;
- return ret;
- }
- if(n == 3) {
- debug("3!");
- if(!ramka) {
- return RU+RI+RI+LD+LU+LU+RI+LD+LD+LU+RU+RU;
- }
- }
- if(n & 1) {
- assert(ramka);
- string ret = RU + solver(n - 1, true) + rp(RD + RU, n - 1) + RD + rp(LE, n);
- return ret;
- }
- else {
- string ret = "";
- if(n % 4 == 2) {
- ret = RU + rp(solver((n - 2) / 2, false), 2);
- ret += rp(RD, (n - 2) / 2) + trap((n - 2) / 2) + rp(LE, (n - 2) / 2) + rp(RD, (n - 2) / 2) + rp(LE, (n - 2) / 2);
- }
- else {
- debug("!!!");
- ret = RU + solver(n - 2, true);
- }
- ret += rp(RD + RU, n - 2) + RD + RU + rp(LE + RU, n - 1);
- if(ramka)
- ret += rp(RD, n) + rp(LE, n);
- return ret;
- }
- };
- ll n;
- string s;
- cin >> n ;
- cout << solver(n, true).data() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement