답안 #144541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144541 2019-08-17T06:06:22 Z Plasmatic Toys (CEOI18_toy) C++11
79 / 100
5000 ms 3720 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

// Defines and one-liners
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
template <typename T> inline T& back(vector<T> &vec) { return *(vec.end() - 1); }
template <typename T> inline void pop(vector<T> &vec) { return vec.erase(vec.end() - 1); }

// Scan, Debug, and other nonsense
template <typename T> ostream& operator<<(ostream& out,vector<T> iter){out<<"[";for(auto t:iter){out<<t<<", ";}out<<"]";return out;}
template <typename T> void printArray(ostream& out,T* arr,int sz){out<<"[";for(int i=0;i<sz;i++){out<<arr[i]<<", "; } out<<"]";}
#define OUT_OPERATOR(type, propa, propb) ostream& operator<<(ostream& out,type obj){out<<"("<<#propa<<"="<<obj. propa<<", "<<#propb<<"="<<obj. propb<<")";return out;}

void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F f,R... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

vector<int> cfactors;

template <int MAX>
struct PrimeSieve {
    bool isPrime[MAX]; vector<int> primes;
    PrimeSieve() {}
    inline void doWithFactor(int x) { cfactors.push_back(x); }
    // inline void doWithPrimeFactors(vector<pair<int, int>> &facts) { assert(("Needs to be implemented!", 0)); }
    void calc() {
        memset(isPrime, true, sizeof isPrime);
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i < MAX; i++) {
            if (isPrime[i]) {
                for (int j = i + i; j < MAX; j += i)
                    isPrime[j] = false;
                primes.push_back(i);
            }
        }
    }
    void factor(int v, bool prime_factor) { // if prime_factor is true, it will only prime factor the number
        int sqv = sqrt(v);
        vector<pair<int, int>> facts;

        for (int prime : primes) {
            if (prime > sqv)
                break;

            int cnt = 0;
            while (v % prime == 0) {
                v /= prime;
                cnt++;
            }

            if (cnt)
                facts.push_back(make_pair(prime, cnt));
        }
        if (v > 1)
            facts.push_back(make_pair(v, 1));

        // if (!prime_factor)
            factorRec(1, 0, facts.size(), facts);
        // else
        //     doWithPrimeFactors(facts);
    }
    void factorRec(int cur, int pos, int sz, vector<pair<int, int>> &facts) {
        if (pos == sz) {
            doWithFactor(cur);
            return;
        }

        for (int i = 0; i <= facts[pos].second; i++) {
            factorRec(cur, pos + 1, sz, facts);
            cur *= facts[pos].first;
        }
    }
};

const int MPS = 32001, SM = 5001;
int n;
set<int> ss;
PrimeSieve<MPS> sieve;
unordered_map<int, int> mp;
bitset<SM> mp2[SM];

void rec(int left, int tc) {
    if (left == 1) {
        ss.insert(tc);
        return;
    }

    if (left < MPS && sieve.isPrime[left]) {
        ss.insert(tc + left - 1);
        return;
    }

    if (left < SM && tc < SM) {
        if (mp2[left][tc])
            return;
        mp2[left][tc] = true;
    }
    else {
        auto ptr = mp.find(left);
        if (ptr != mp.end() && ptr->second == tc)
            return;
        mp[left] = tc;
    }

    cfactors.clear();
    sieve.factor(left, false);

    // debug(left, tc, cfactors);

    vector<int> cfactors2 = vector<int>(cfactors.begin() + 1, cfactors.end());
    for (int factor : cfactors2) {
        rec(left / factor, tc + factor - 1);
    }
}

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

    scan(n);

    sieve.calc();

    rec(n, 0);

    cout << ss.size() << "\n";
    for (auto x : ss)
        cout << x << " ";
    cout << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 428 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 516 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 428 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 516 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 5 ms 760 KB Output is correct
51 Correct 5 ms 736 KB Output is correct
52 Correct 5 ms 760 KB Output is correct
53 Correct 5 ms 760 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 7 ms 760 KB Output is correct
56 Correct 6 ms 760 KB Output is correct
57 Correct 6 ms 788 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 3 ms 504 KB Output is correct
61 Correct 2 ms 632 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 4 ms 632 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 3 ms 504 KB Output is correct
70 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 428 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 516 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 5 ms 760 KB Output is correct
51 Correct 5 ms 736 KB Output is correct
52 Correct 5 ms 760 KB Output is correct
53 Correct 5 ms 760 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 7 ms 760 KB Output is correct
56 Correct 6 ms 760 KB Output is correct
57 Correct 6 ms 788 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 3 ms 504 KB Output is correct
61 Correct 2 ms 632 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 4 ms 632 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 3 ms 504 KB Output is correct
70 Correct 3 ms 632 KB Output is correct
71 Correct 1459 ms 2892 KB Output is correct
72 Correct 748 ms 2516 KB Output is correct
73 Correct 1276 ms 2652 KB Output is correct
74 Correct 468 ms 2228 KB Output is correct
75 Correct 588 ms 2148 KB Output is correct
76 Correct 3888 ms 3068 KB Output is correct
77 Correct 4042 ms 2628 KB Output is correct
78 Correct 2607 ms 2816 KB Output is correct
79 Correct 2707 ms 2640 KB Output is correct
80 Correct 2 ms 376 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 11 ms 504 KB Output is correct
83 Correct 336 ms 1080 KB Output is correct
84 Correct 180 ms 1372 KB Output is correct
85 Correct 53 ms 680 KB Output is correct
86 Correct 3 ms 504 KB Output is correct
87 Correct 419 ms 1144 KB Output is correct
88 Correct 3 ms 376 KB Output is correct
89 Correct 2 ms 376 KB Output is correct
90 Correct 3 ms 504 KB Output is correct
91 Correct 48 ms 1016 KB Output is correct
92 Correct 176 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 428 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 516 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 380 KB Output is correct
35 Correct 3 ms 380 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 5 ms 760 KB Output is correct
51 Correct 5 ms 736 KB Output is correct
52 Correct 5 ms 760 KB Output is correct
53 Correct 5 ms 760 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 7 ms 760 KB Output is correct
56 Correct 6 ms 760 KB Output is correct
57 Correct 6 ms 788 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 3 ms 504 KB Output is correct
61 Correct 2 ms 632 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 2 ms 504 KB Output is correct
65 Correct 4 ms 632 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 376 KB Output is correct
69 Correct 3 ms 504 KB Output is correct
70 Correct 3 ms 632 KB Output is correct
71 Correct 1459 ms 2892 KB Output is correct
72 Correct 748 ms 2516 KB Output is correct
73 Correct 1276 ms 2652 KB Output is correct
74 Correct 468 ms 2228 KB Output is correct
75 Correct 588 ms 2148 KB Output is correct
76 Correct 3888 ms 3068 KB Output is correct
77 Correct 4042 ms 2628 KB Output is correct
78 Correct 2607 ms 2816 KB Output is correct
79 Correct 2707 ms 2640 KB Output is correct
80 Correct 2 ms 376 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 11 ms 504 KB Output is correct
83 Correct 336 ms 1080 KB Output is correct
84 Correct 180 ms 1372 KB Output is correct
85 Correct 53 ms 680 KB Output is correct
86 Correct 3 ms 504 KB Output is correct
87 Correct 419 ms 1144 KB Output is correct
88 Correct 3 ms 376 KB Output is correct
89 Correct 2 ms 376 KB Output is correct
90 Correct 3 ms 504 KB Output is correct
91 Correct 48 ms 1016 KB Output is correct
92 Correct 176 ms 1884 KB Output is correct
93 Execution timed out 5008 ms 3720 KB Time limit exceeded
94 Halted 0 ms 0 KB -