#include <bits/stdc++.h> #include <random> #define ll long long int #define pb push_back #define st first #define nd second #define pii pair<int,int> #define mp make_pair #define pll pair<long long,long long> #define ld long double #define ull unsigned long long #define mt make_tuple using namespace std; string repeat(ll cnt, string s){ if(cnt == 0) return ""; if(cnt == 1){ return s; } if(cnt <= 9){ string ret = ""; ret += to_string(cnt); ret += "["; ret += s; ret += "]"; return ret; } string ret = "9["; ret += repeat(cnt / 9, s); ret += "]"; if(cnt % 9 != 0){ ret += to_string(cnt % 9); ret += "["; ret += s; ret += "]"; } return ret; } vector<char> dirs = {'A', 'B', 'C', 'D', 'E', 'F'}; char rotate_once(char dir){ int pos = 0; while(dirs[pos] != dir) pos++; pos -= 2; if(pos < 0) pos += 6; return dirs[pos]; } string ans = ""; string rotate_string(string s, int times){ for(int i=0;i<(int)s.size();i++){ for(int j=0;j<times;j++){ s[i] = rotate_once(s[i]); } } return s; } void rombik(ll bok, int start){ vector<string> patern(4, ""); patern[0] = "C"; patern[1] = "AE"; patern[2] = "A"; patern[3] = "E"; for(int i=0;i<4;i++){ patern[i] = rotate_string(patern[i], start); } string raz = repeat(bok, patern[0]) + repeat(bok - 1, patern[1]) + repeat(1LL, patern[2]); ans += repeat(bok, raz); ans += repeat(bok, patern[3]); } void triangle_code(ll n, int start, bool ma_spod){ if(n == 0) return; if(ma_spod){ if(n % 2 == 0){ vector<string> pattern(4, ""); pattern[0] = "C"; pattern[1] = "A"; pattern[2] = "EA"; pattern[3] = "E"; for(int i=0;i<4;i++){ pattern[i] = rotate_string(pattern[i], start); } string code = repeat(n, pattern[0]) + repeat(1LL, pattern[1]) + repeat(n - 1, pattern[2]); ans += code; triangle_code(n - 1, start, ma_spod); ans += repeat(1LL, pattern[3]); return; } else{ // juz dobre if(n == 1){ string pattern = "CAE"; pattern = rotate_string(pattern, start); ans += repeat(1LL, pattern); return; } else{ vector<string> pattern(2, ""); pattern[0] = "C"; pattern[1] = "A"; for(int i=0;i<2;i++){ pattern[i] = rotate_string(pattern[i], start); } ans += repeat(n, pattern[0]); ans += repeat(n, pattern[1]); ans += "2["; triangle_code((n - 1) / 2, (start + 2) % 3, false); ans += "]"; string es = "EA"; es = rotate_string(es, start); ans += repeat(n - 1, es); rombik((n - 1) / 2, start); string fin = "E"; fin = rotate_string(fin, start); ans += repeat(1LL, fin); return; } } } else{ // bez spodziku vector<string> patern(3, ""); patern[0] = "E"; patern[1] = "CE"; patern[2] = "C"; for(int i=0;i<3;i++){ patern[i] = rotate_string(patern[i], (start + 1) % 3); } ans += repeat(1LL, patern[0]); ans += repeat(n - 1, patern[1]); triangle_code(n - 1, (start + 2) % 3, true); ans += repeat(1LL, patern[2]); } } void solve(){ ll n; cin >> n; triangle_code(n, 0, true); cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int tt = 1; // cin >> tt; while(tt--) solve(); return 0; } /* g++ -std=c++17 -Wall -Wshadow -Wextra -O2 -fsanitize=address -fsanitize=undefined c.cpp -o c */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | #include <bits/stdc++.h> #include <random> #define ll long long int #define pb push_back #define st first #define nd second #define pii pair<int,int> #define mp make_pair #define pll pair<long long,long long> #define ld long double #define ull unsigned long long #define mt make_tuple using namespace std; string repeat(ll cnt, string s){ if(cnt == 0) return ""; if(cnt == 1){ return s; } if(cnt <= 9){ string ret = ""; ret += to_string(cnt); ret += "["; ret += s; ret += "]"; return ret; } string ret = "9["; ret += repeat(cnt / 9, s); ret += "]"; if(cnt % 9 != 0){ ret += to_string(cnt % 9); ret += "["; ret += s; ret += "]"; } return ret; } vector<char> dirs = {'A', 'B', 'C', 'D', 'E', 'F'}; char rotate_once(char dir){ int pos = 0; while(dirs[pos] != dir) pos++; pos -= 2; if(pos < 0) pos += 6; return dirs[pos]; } string ans = ""; string rotate_string(string s, int times){ for(int i=0;i<(int)s.size();i++){ for(int j=0;j<times;j++){ s[i] = rotate_once(s[i]); } } return s; } void rombik(ll bok, int start){ vector<string> patern(4, ""); patern[0] = "C"; patern[1] = "AE"; patern[2] = "A"; patern[3] = "E"; for(int i=0;i<4;i++){ patern[i] = rotate_string(patern[i], start); } string raz = repeat(bok, patern[0]) + repeat(bok - 1, patern[1]) + repeat(1LL, patern[2]); ans += repeat(bok, raz); ans += repeat(bok, patern[3]); } void triangle_code(ll n, int start, bool ma_spod){ if(n == 0) return; if(ma_spod){ if(n % 2 == 0){ vector<string> pattern(4, ""); pattern[0] = "C"; pattern[1] = "A"; pattern[2] = "EA"; pattern[3] = "E"; for(int i=0;i<4;i++){ pattern[i] = rotate_string(pattern[i], start); } string code = repeat(n, pattern[0]) + repeat(1LL, pattern[1]) + repeat(n - 1, pattern[2]); ans += code; triangle_code(n - 1, start, ma_spod); ans += repeat(1LL, pattern[3]); return; } else{ // juz dobre if(n == 1){ string pattern = "CAE"; pattern = rotate_string(pattern, start); ans += repeat(1LL, pattern); return; } else{ vector<string> pattern(2, ""); pattern[0] = "C"; pattern[1] = "A"; for(int i=0;i<2;i++){ pattern[i] = rotate_string(pattern[i], start); } ans += repeat(n, pattern[0]); ans += repeat(n, pattern[1]); ans += "2["; triangle_code((n - 1) / 2, (start + 2) % 3, false); ans += "]"; string es = "EA"; es = rotate_string(es, start); ans += repeat(n - 1, es); rombik((n - 1) / 2, start); string fin = "E"; fin = rotate_string(fin, start); ans += repeat(1LL, fin); return; } } } else{ // bez spodziku vector<string> patern(3, ""); patern[0] = "E"; patern[1] = "CE"; patern[2] = "C"; for(int i=0;i<3;i++){ patern[i] = rotate_string(patern[i], (start + 1) % 3); } ans += repeat(1LL, patern[0]); ans += repeat(n - 1, patern[1]); triangle_code(n - 1, (start + 2) % 3, true); ans += repeat(1LL, patern[2]); } } void solve(){ ll n; cin >> n; triangle_code(n, 0, true); cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int tt = 1; // cin >> tt; while(tt--) solve(); return 0; } /* g++ -std=c++17 -Wall -Wshadow -Wextra -O2 -fsanitize=address -fsanitize=undefined c.cpp -o c */ |