记录编号 571415 评测结果 AAAAAAAAAA
题目名称 [金陵中学2007] 最优分解方案 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.692 s
提交时间 2022-05-21 20:25:32 内存使用 2.96 MiB
显示代码纯文本
#include <bits/stdc++.h>

class Bigint {
    private:
        std::vector<int> num;
    public:
        Bigint () {}
        Bigint (const char* rst) {
            int len = strlen(rst);
            for(int i = len - 1; i >= 0; -- i) num.emplace_back(rst[i] - 48);
        }
        Bigint (const int rst) {
            char tmp[100];
            sprintf(tmp, "%d", rst);
            *this = tmp;
        }
        Bigint operator + (const Bigint& rst) {
            Bigint ret;
            int t = 0;
            for(int i = 0; i < (int) num.size() || i < (int) rst.num.size() || t; ++ i) {
                if(i < (int) num.size()) t += num[i];
                if(i < (int) rst.num.size()) t += rst.num[i];
                ret.num.emplace_back(t % 10);
                t /= 10;
            }
            return ret;
        }
        Bigint operator += (Bigint rst) {
            *this = *this + rst;
            return *this;
        }
        Bigint operator * (int rst) {
            Bigint ret;
            int t = 0;
            for(int i = 0; i < (int) num.size() || t; ++ i) {
                if(i < (int) num.size()) t += num[i] * rst; 
                ret.num.emplace_back(t % 10);
                t /= 10;
            }
            while(ret.num.size() > 1 && !ret.num.back()) ret.num.pop_back();
            return ret;
        }
        Bigint operator * (Bigint& rst) {
            Bigint ret;
            for(int i = rst.num.size() - 1; i >= 0; -- i) {
                ret = ret * 10;
                ret += *this * rst.num[i];
            }
            return ret;
        }
        friend bool operator < (Bigint lst, Bigint rst) {
            if(lst.num.size() > rst.num.size()) return false;
            else if(lst.num.size() < rst.num.size()) return true;
            else {
                for(int i = lst.num.size() - 1; i >= 0; -- i) {
                    if(lst.num[i] < rst.num[i]) return true;
                    if(lst.num[i] > rst.num[i]) return false;
                }
            }
            return false;
        }
        friend std::ostream& operator << (std::ostream& os, Bigint rst) {
            for(int i = rst.num.size() - 1; i >= 0; -- i) os << rst.num[i];
            return os;
        }
};

const int N = 1010;
int n;
Bigint f[N];
 
int main() {
    freopen("best.in", "r", stdin); 
    freopen("best.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    for (int i = 1; i <= n; ++ i) 
        for (int j = n; j >= i; -- j)
            f[j] = std::max({Bigint(i), f[j], f[j - i] * i});
    std::cout << f[n] << '\n';
    return 0;
}