제출 #1175028

#제출 시각아이디문제언어결과실행 시간메모리
1175028SulAToys (CEOI18_toy)C++20
59 / 100
5093 ms744 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define popcount __builtin_popcountll
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

vector<int> merge(const vector<int>& a, const vector<int>& b) {
    vector<int> res;
    int ptr1 = 0, ptr2 = 0;
    while (ptr1 < a.size() && ptr2 < b.size()) {

        int val = min(a[ptr1], b[ptr2]);
        res.push_back(val);
        while (ptr1 < a.size() && a[ptr1] == val)
            ptr1++;
        while (ptr2 < b.size() && b[ptr2] == val)
            ptr2++;
    }
    while (ptr1 < a.size())
        res.push_back(a[ptr1++]);
    while (ptr2 < b.size())
        res.push_back(b[ptr2++]);
    return res;
}

vector<int> solve(int n) {
    vector<int> res { n - 1 };
    for (int i = 2; i*i <= n; i++) if (n % i == 0) {
        auto list = solve(i);
        for (int& x : list)
            x += n/i - 1;
        res = merge(res, list);
        if (i*i != n) {
            list = solve(n/i);
            for (int& x : list)
                x += i - 1;
            res = merge(res, list);
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    auto ans = solve(n);
    cout << ans.size() << "\n";
    for (int x : ans) cout << x << " ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...