#include <bits/stdc++.h> using namespace std; using lint = long long; using llf = long double; using pi = array<lint, 2>; #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() const int MAXN = 6005; const int mod = 1e9 + 7; int dp[4][MAXN]; string rep(string base, lint q) { if (q == 0) return ""; if (q == 1) return base; if (q <= 9) { return to_string(q) + "[" + base + "]"; } pi ans{lint(1e18), -1}; for (int i = 2; i <= 9; i++) { ans = min(ans, {dp[sz(base) - 1][q / i] + (q % i ? dp[sz(base) - 1][q % i] : 0), i}); } int d = ans[1]; return to_string(d) + "[" + rep(base, q / d) + "]" + rep(base, q % d); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(69); for (int i = 0; i < 4; i++) { dp[i][1] = i + 1; for (int j = 2; j <= 9; j++) dp[i][j] = 2 + i + 1 + 1; for (int j = 10; j <= 6000; j++) { dp[i][j] = 1e9; for (int k = 2; k <= 9; k++) { dp[i][j] = min(dp[i][j], dp[i][j / k] + 3 + (j % k ? dp[i][j % k] : 0)); } } } lint n; cin >> n; string ans; for (int i = 1; i <= n; i++) { if (i % 2 == 1) ans += rep("AEAC", n - i) + "AE"; else ans += "E" + rep("CE", n - i); } ans += rep("C", n); cout << ans << "\n"; }
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 | #include <bits/stdc++.h> using namespace std; using lint = long long; using llf = long double; using pi = array<lint, 2>; #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() const int MAXN = 6005; const int mod = 1e9 + 7; int dp[4][MAXN]; string rep(string base, lint q) { if (q == 0) return ""; if (q == 1) return base; if (q <= 9) { return to_string(q) + "[" + base + "]"; } pi ans{lint(1e18), -1}; for (int i = 2; i <= 9; i++) { ans = min(ans, {dp[sz(base) - 1][q / i] + (q % i ? dp[sz(base) - 1][q % i] : 0), i}); } int d = ans[1]; return to_string(d) + "[" + rep(base, q / d) + "]" + rep(base, q % d); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(69); for (int i = 0; i < 4; i++) { dp[i][1] = i + 1; for (int j = 2; j <= 9; j++) dp[i][j] = 2 + i + 1 + 1; for (int j = 10; j <= 6000; j++) { dp[i][j] = 1e9; for (int k = 2; k <= 9; k++) { dp[i][j] = min(dp[i][j], dp[i][j / k] + 3 + (j % k ? dp[i][j % k] : 0)); } } } lint n; cin >> n; string ans; for (int i = 1; i <= n; i++) { if (i % 2 == 1) ans += rep("AEAC", n - i) + "AE"; else ans += "E" + rep("CE", n - i); } ans += rep("C", n); cout << ans << "\n"; } |