Advertisement
Guest User

Untitled

a guest
Dec 14th, 2022
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. //Franciszek Witt
  2. //NIENAWIDZE CF-LIKE CONSTRUCTIVE ZADAN
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define FOR(i,l,r) for(int i=(l);i<=(r);++i)
  6. #define REP(i,n) FOR(i,0,(n)-1)
  7. #define ssize(x) int(x.size())
  8. template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
  9. 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<<'}';}
  10. #ifdef DEBUG
  11. #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
  12. #else
  13. #define debug(...) {}
  14. #endif
  15. typedef long long ll;
  16. int main() {
  17.     ios_base::sync_with_stdio(0);
  18.     cin.tie(0);
  19.  
  20.     auto tos = [&] (int x) {
  21.         assert(1 <= x && x <= 9);
  22.         return string("") + char(x + '0');
  23.     };
  24.  
  25.     function<string(const string, ll)> rp = [&] (const string s, ll n) {
  26.         if(n == 0 || ssize(s) == 0)
  27.             return string("");
  28.         if(n == 1)
  29.             return s;
  30.         if(n < 10)
  31.             return tos(n) + "[" + s + "]";
  32.         if(n % 9 == 0)
  33.             return "9[" + rp(s, n / 9) + "]";
  34.         return rp(s, n % 9) + rp(s, n - (n % 9));
  35.     };
  36.  
  37.     const string RI = "A", RD = "B", LD = "C", LE = "D", LU = "E", RU = "F";
  38.  
  39.     auto trap = [&] (ll n) {
  40.         if(n == 0)
  41.             return string("");
  42.         return rp(rp(LD + LU, n - 1) + LD + rp(RI, n), n) + rp(LU, n);
  43.     };
  44.  
  45.     //jezeli ramka to wracamy w to samo miejsce
  46.     //jak bez ramki to przechodzimy krawedzia z ramka
  47.     function<string(ll, bool)> solver = [&] (ll n, bool ramka) {
  48.         debug(n, ramka);
  49.         if(n == 0)
  50.             return string("");
  51.         if(n == 1) {
  52.             string ret = RU;
  53.             if(ramka)
  54.                 ret += RD + LE;
  55.             return ret;
  56.         }
  57.         if(n == 3) {
  58.             debug("3!");
  59.             if(!ramka) {
  60.                 return RU+RI+RI+LD+LU+LU+RI+LD+LD+LU+RU+RU;
  61.             }
  62.         }
  63.         if(n & 1) {
  64.             assert(ramka);
  65.             string ret = RU + solver(n - 1, true) + rp(RD + RU, n - 1) + RD + rp(LE, n);
  66.             return ret;
  67.         }
  68.         else {
  69.             string ret = "";
  70.             if(n % 4 == 2) {
  71.                 ret = RU + rp(solver((n - 2) / 2, false), 2);
  72.                 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);
  73.             }
  74.             else {
  75.                 debug("!!!");
  76.                 ret = RU + solver(n - 2, true);
  77.             }
  78.             ret += rp(RD + RU, n - 2) + RD + RU + rp(LE + RU, n - 1);
  79.             if(ramka)
  80.                 ret += rp(RD, n) + rp(LE, n);
  81.             return ret;
  82.         }
  83.  
  84.     };
  85.  
  86.     ll n;
  87.     string s;
  88.     cin >> n ;
  89.     cout << solver(n, true).data() << endl;
  90.  
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement