답안 #493229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493229 2021-12-10T13:12:17 Z blue Toys (CEOI18_toy) C++17
79 / 100
5000 ms 65772 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);
vi solved2(1+40'000, 0);

void solve(long long i)
{
    // cerr << "solve " << i << '\n';
    // if(solved[i]) return;
    // solved[i] = 1;
    if(i*i <= n)
    {
        if(solved[i]) return;
        else solved[i] = 1;
    }
    else
    {
        if(solved2[n/i]) return;
        else solved2[n/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(i*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 << "1\n 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 = res2[1];

    // 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 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 1 ms 2508 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 2 ms 2508 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2508 KB Output is correct
11 Correct 1 ms 2508 KB Output is correct
12 Correct 1 ms 2628 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2508 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 1 ms 2508 KB Output is correct
24 Correct 1 ms 2508 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 1 ms 2508 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 2 ms 2508 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2508 KB Output is correct
11 Correct 1 ms 2508 KB Output is correct
12 Correct 1 ms 2628 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2508 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 1 ms 2508 KB Output is correct
24 Correct 1 ms 2508 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
26 Correct 2 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 1 ms 2508 KB Output is correct
29 Correct 2 ms 2508 KB Output is correct
30 Correct 1 ms 2508 KB Output is correct
31 Correct 2 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 2 ms 2508 KB Output is correct
34 Correct 1 ms 2508 KB Output is correct
35 Correct 2 ms 2508 KB Output is correct
36 Correct 1 ms 2508 KB Output is correct
37 Correct 2 ms 2508 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2508 KB Output is correct
40 Correct 2 ms 2508 KB Output is correct
41 Correct 1 ms 2508 KB Output is correct
42 Correct 1 ms 2404 KB Output is correct
43 Correct 1 ms 2508 KB Output is correct
44 Correct 1 ms 2508 KB Output is correct
45 Correct 1 ms 2508 KB Output is correct
46 Correct 2 ms 2508 KB Output is correct
47 Correct 2 ms 2508 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 2 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 1 ms 2508 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 2 ms 2508 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2508 KB Output is correct
11 Correct 1 ms 2508 KB Output is correct
12 Correct 1 ms 2628 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2508 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 1 ms 2508 KB Output is correct
24 Correct 1 ms 2508 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
26 Correct 2 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 1 ms 2508 KB Output is correct
29 Correct 2 ms 2508 KB Output is correct
30 Correct 1 ms 2508 KB Output is correct
31 Correct 2 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 2 ms 2508 KB Output is correct
34 Correct 1 ms 2508 KB Output is correct
35 Correct 2 ms 2508 KB Output is correct
36 Correct 1 ms 2508 KB Output is correct
37 Correct 2 ms 2508 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2508 KB Output is correct
40 Correct 2 ms 2508 KB Output is correct
41 Correct 1 ms 2508 KB Output is correct
42 Correct 1 ms 2404 KB Output is correct
43 Correct 1 ms 2508 KB Output is correct
44 Correct 1 ms 2508 KB Output is correct
45 Correct 1 ms 2508 KB Output is correct
46 Correct 2 ms 2508 KB Output is correct
47 Correct 2 ms 2508 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 2 ms 2508 KB Output is correct
50 Correct 4 ms 2636 KB Output is correct
51 Correct 4 ms 2636 KB Output is correct
52 Correct 4 ms 2636 KB Output is correct
53 Correct 4 ms 2664 KB Output is correct
54 Correct 2 ms 2508 KB Output is correct
55 Correct 8 ms 2764 KB Output is correct
56 Correct 8 ms 2696 KB Output is correct
57 Correct 6 ms 2764 KB Output is correct
58 Correct 2 ms 2508 KB Output is correct
59 Correct 2 ms 2508 KB Output is correct
60 Correct 2 ms 2508 KB Output is correct
61 Correct 4 ms 2636 KB Output is correct
62 Correct 2 ms 2508 KB Output is correct
63 Correct 2 ms 2508 KB Output is correct
64 Correct 2 ms 2508 KB Output is correct
65 Correct 4 ms 2636 KB Output is correct
66 Correct 2 ms 2508 KB Output is correct
67 Correct 2 ms 2508 KB Output is correct
68 Correct 2 ms 2508 KB Output is correct
69 Correct 2 ms 2508 KB Output is correct
70 Correct 2 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 1 ms 2508 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 2 ms 2508 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2508 KB Output is correct
11 Correct 1 ms 2508 KB Output is correct
12 Correct 1 ms 2628 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2508 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 1 ms 2508 KB Output is correct
24 Correct 1 ms 2508 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
26 Correct 2 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 1 ms 2508 KB Output is correct
29 Correct 2 ms 2508 KB Output is correct
30 Correct 1 ms 2508 KB Output is correct
31 Correct 2 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 2 ms 2508 KB Output is correct
34 Correct 1 ms 2508 KB Output is correct
35 Correct 2 ms 2508 KB Output is correct
36 Correct 1 ms 2508 KB Output is correct
37 Correct 2 ms 2508 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2508 KB Output is correct
40 Correct 2 ms 2508 KB Output is correct
41 Correct 1 ms 2508 KB Output is correct
42 Correct 1 ms 2404 KB Output is correct
43 Correct 1 ms 2508 KB Output is correct
44 Correct 1 ms 2508 KB Output is correct
45 Correct 1 ms 2508 KB Output is correct
46 Correct 2 ms 2508 KB Output is correct
47 Correct 2 ms 2508 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 2 ms 2508 KB Output is correct
50 Correct 4 ms 2636 KB Output is correct
51 Correct 4 ms 2636 KB Output is correct
52 Correct 4 ms 2636 KB Output is correct
53 Correct 4 ms 2664 KB Output is correct
54 Correct 2 ms 2508 KB Output is correct
55 Correct 8 ms 2764 KB Output is correct
56 Correct 8 ms 2696 KB Output is correct
57 Correct 6 ms 2764 KB Output is correct
58 Correct 2 ms 2508 KB Output is correct
59 Correct 2 ms 2508 KB Output is correct
60 Correct 2 ms 2508 KB Output is correct
61 Correct 4 ms 2636 KB Output is correct
62 Correct 2 ms 2508 KB Output is correct
63 Correct 2 ms 2508 KB Output is correct
64 Correct 2 ms 2508 KB Output is correct
65 Correct 4 ms 2636 KB Output is correct
66 Correct 2 ms 2508 KB Output is correct
67 Correct 2 ms 2508 KB Output is correct
68 Correct 2 ms 2508 KB Output is correct
69 Correct 2 ms 2508 KB Output is correct
70 Correct 2 ms 2508 KB Output is correct
71 Correct 1209 ms 34300 KB Output is correct
72 Correct 774 ms 28044 KB Output is correct
73 Correct 1149 ms 34860 KB Output is correct
74 Correct 535 ms 17856 KB Output is correct
75 Correct 673 ms 27940 KB Output is correct
76 Correct 2319 ms 64576 KB Output is correct
77 Correct 2440 ms 65772 KB Output is correct
78 Correct 1777 ms 58120 KB Output is correct
79 Correct 1844 ms 59356 KB Output is correct
80 Correct 483 ms 2508 KB Output is correct
81 Correct 502 ms 2508 KB Output is correct
82 Correct 337 ms 3020 KB Output is correct
83 Correct 483 ms 8988 KB Output is correct
84 Correct 282 ms 9724 KB Output is correct
85 Correct 508 ms 4160 KB Output is correct
86 Correct 485 ms 2508 KB Output is correct
87 Correct 624 ms 8952 KB Output is correct
88 Correct 490 ms 2508 KB Output is correct
89 Correct 490 ms 2628 KB Output is correct
90 Correct 493 ms 2508 KB Output is correct
91 Correct 518 ms 3468 KB Output is correct
92 Correct 587 ms 9048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Correct 1 ms 2508 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 1 ms 2508 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 2 ms 2508 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2508 KB Output is correct
10 Correct 1 ms 2508 KB Output is correct
11 Correct 1 ms 2508 KB Output is correct
12 Correct 1 ms 2628 KB Output is correct
13 Correct 1 ms 2508 KB Output is correct
14 Correct 1 ms 2508 KB Output is correct
15 Correct 1 ms 2508 KB Output is correct
16 Correct 2 ms 2508 KB Output is correct
17 Correct 1 ms 2508 KB Output is correct
18 Correct 1 ms 2508 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2508 KB Output is correct
21 Correct 1 ms 2508 KB Output is correct
22 Correct 1 ms 2508 KB Output is correct
23 Correct 1 ms 2508 KB Output is correct
24 Correct 1 ms 2508 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
26 Correct 2 ms 2508 KB Output is correct
27 Correct 2 ms 2508 KB Output is correct
28 Correct 1 ms 2508 KB Output is correct
29 Correct 2 ms 2508 KB Output is correct
30 Correct 1 ms 2508 KB Output is correct
31 Correct 2 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 2 ms 2508 KB Output is correct
34 Correct 1 ms 2508 KB Output is correct
35 Correct 2 ms 2508 KB Output is correct
36 Correct 1 ms 2508 KB Output is correct
37 Correct 2 ms 2508 KB Output is correct
38 Correct 1 ms 2508 KB Output is correct
39 Correct 1 ms 2508 KB Output is correct
40 Correct 2 ms 2508 KB Output is correct
41 Correct 1 ms 2508 KB Output is correct
42 Correct 1 ms 2404 KB Output is correct
43 Correct 1 ms 2508 KB Output is correct
44 Correct 1 ms 2508 KB Output is correct
45 Correct 1 ms 2508 KB Output is correct
46 Correct 2 ms 2508 KB Output is correct
47 Correct 2 ms 2508 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 2 ms 2508 KB Output is correct
50 Correct 4 ms 2636 KB Output is correct
51 Correct 4 ms 2636 KB Output is correct
52 Correct 4 ms 2636 KB Output is correct
53 Correct 4 ms 2664 KB Output is correct
54 Correct 2 ms 2508 KB Output is correct
55 Correct 8 ms 2764 KB Output is correct
56 Correct 8 ms 2696 KB Output is correct
57 Correct 6 ms 2764 KB Output is correct
58 Correct 2 ms 2508 KB Output is correct
59 Correct 2 ms 2508 KB Output is correct
60 Correct 2 ms 2508 KB Output is correct
61 Correct 4 ms 2636 KB Output is correct
62 Correct 2 ms 2508 KB Output is correct
63 Correct 2 ms 2508 KB Output is correct
64 Correct 2 ms 2508 KB Output is correct
65 Correct 4 ms 2636 KB Output is correct
66 Correct 2 ms 2508 KB Output is correct
67 Correct 2 ms 2508 KB Output is correct
68 Correct 2 ms 2508 KB Output is correct
69 Correct 2 ms 2508 KB Output is correct
70 Correct 2 ms 2508 KB Output is correct
71 Correct 1209 ms 34300 KB Output is correct
72 Correct 774 ms 28044 KB Output is correct
73 Correct 1149 ms 34860 KB Output is correct
74 Correct 535 ms 17856 KB Output is correct
75 Correct 673 ms 27940 KB Output is correct
76 Correct 2319 ms 64576 KB Output is correct
77 Correct 2440 ms 65772 KB Output is correct
78 Correct 1777 ms 58120 KB Output is correct
79 Correct 1844 ms 59356 KB Output is correct
80 Correct 483 ms 2508 KB Output is correct
81 Correct 502 ms 2508 KB Output is correct
82 Correct 337 ms 3020 KB Output is correct
83 Correct 483 ms 8988 KB Output is correct
84 Correct 282 ms 9724 KB Output is correct
85 Correct 508 ms 4160 KB Output is correct
86 Correct 485 ms 2508 KB Output is correct
87 Correct 624 ms 8952 KB Output is correct
88 Correct 490 ms 2508 KB Output is correct
89 Correct 490 ms 2628 KB Output is correct
90 Correct 493 ms 2508 KB Output is correct
91 Correct 518 ms 3468 KB Output is correct
92 Correct 587 ms 9048 KB Output is correct
93 Execution timed out 5064 ms 61460 KB Time limit exceeded
94 Halted 0 ms 0 KB -