답안 #493228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493228 2021-12-10T13:10:32 Z blue Toys (CEOI18_toy) C++17
0 / 100
2 ms 2252 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
using namespace std;

#define sz(x) (int(x.size()))
using vi = vector<int>;

// map< int, vector<int> > res;

vi sf;

long long n;

vector<int> res[40'000]; //i*i <= n
vector<int> res2[40'000]; //i*i >= n, access n/i.

vi solved(1+40'000, 0);

void solve(long long i)
{
    // cerr << "solve " << i << '\n';
    if(solved[i]) return;
    solved[i] = 1;
    // cerr << "\n\n\n";
    // cerr << "solve:  " << i << '\n';
    // cerr << "cond = " << int(res.find(i) != res.end()) << '\n';
    // if(res.find(i) != res.end()) return;
    // cerr << "entered\n";

    vi ans(1, i-1);
    // for(int j = 2; j < i && j*j <= i; j++)

    // cerr << "#\n";
    // for(int y: sf) cerr << "y = " << y << '\n';
    // cerr << "#2\n";

    for(int j: sf)
    {
        // cerr << "j = " << j << '\n';
        if(j >= i || j*j > i) break;
        if(i % j == 0)
        {
            // cerr << i << " -> " << j << '\n';
            long long u = j;
            long long v = i/j;
            solve(u);
            solve(v);
            for(int a: (u*u <= n ? res[u] : res2[n/u]))
                for(int b: (v*v <= n ? res[v] : res2[n/v]))
                    ans.push_back(a+b);
        }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    // for(int a: ans) cerr << "a = " << a << '\n';

    if((long long)(i) * (long long)(i) <= n)
    {
        // cerr << "case 1\n";
        res[i] = ans;
    }
    else
    {
        // cerr << "case 2\n";
        res2[n/i] = ans;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    if(n == 1)
    {
        cout << "0\n";
        return 0;
    }



    for(int i = 2; i <= n; i++)
    {
        // cerr << i << " " << n%i << ' ' << int(n%i == 0) << '\n';
        if(n % i == 0)
            sf.push_back(i);
    }


    solve(n);
    vi ans = n*n <= n ? res[n] : res2[n/n];

    // cerr << "sf init = " ;
    // for(int q: sf) cerr << q << " ";
    // cerr << "\n";

    cout << sz(ans) << '\n';
    for(int r: ans) cout << r << ' ';
    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -