답안 #147799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147799 2019-08-30T16:49:02 Z 12tqian Toys (CEOI18_toy) C++14
79 / 100
5000 ms 15720 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const double PI = 4 * atan(1);

#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const int MAX = 1500;
const int INF = 2e9 + 7;
set<int> ans;
set<int> s;
unordered_map<int, int> um;
unordered_map<int, int> fin;
map<pii, int> use;
vi divisors;
vi nums[MAX];
///index of the divisor, find largest divisor of d less than or
///equal to mx
int val[MAX][MAX];
int get(int d, int mx){
    int l = 0;
    int r = sz(nums[d])-1;
    while(abs(l-r)>1){
        int m = (l + r)/2;
        if(nums[d][m]>mx){
            r = m-1;
        }
        else{
            l = m;
        }
    }
    if(l>r) swap(l, r);
    if(nums[d][r] <= mx) return r;
    return l;
}
int cnt = 0;
void solve(int left, int last, int sum){
    if(left == 1){
        cnt++;
        fin[sum] = 1;
        return;
    }
    int id = um[left];
    int idx;
    if(left <= last) idx = sz(nums[id]) - 1;
    else idx = val[id][um[last]];
    f1r(i, 1, idx+1){
        int divisor = nums[id][i];
        solve(left/divisors[divisor], divisors[divisor], sum + divisors[divisor] - 1);
    }
}
int main(){
    fast_io();
    int n;
   // cin >> n;
    scanf("%d", &n);
    f1r(i, 1, sqrt(n) + 1){
        if(n%i == 0){
            s.insert(i);
            s.insert(n/i);
        }
    }
    for(auto x: s) divisors.eb(x);
    f0r(i, sz(divisors)){
        um[divisors[i]] = i;
        f0r(j, i+1){
            if(divisors[i]%divisors[j] == 0){
                nums[i].eb(j);
            }
        }
    }
    f0r(i, sz(divisors)){
        int best = 0;
        f0r(j, i+1){
            while(best+1<sz(nums[i]) && nums[i][best+1]<= divisors[j]){
                best++;
            }
            val[i][j] = best;
            //val[i][j] = get(i, divisors[j]);
        }
    }
    solve(n, INF, 0);
    for(auto i: fin) ans.insert(i.f);
  //  cout << sz(ans) << endl;
    printf("%d\n", sz(ans));
    for(auto x: ans) printf("%d ", x);
   // cout << endl;
   // cout << cnt << endl;
    return 0;
}

Compilation message

toy.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
toy.cpp: In function 'void io(std::__cxx11::string)':
toy.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
toy.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 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 2 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 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 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 2 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 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 508 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 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 2 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 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 2 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 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 508 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 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 2 ms 504 KB Output is correct
50 Correct 4 ms 988 KB Output is correct
51 Correct 4 ms 1016 KB Output is correct
52 Correct 4 ms 888 KB Output is correct
53 Correct 4 ms 888 KB Output is correct
54 Correct 3 ms 760 KB Output is correct
55 Correct 6 ms 1016 KB Output is correct
56 Correct 6 ms 888 KB Output is correct
57 Correct 5 ms 1016 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 6 ms 632 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 532 KB Output is correct
64 Correct 2 ms 424 KB Output is correct
65 Correct 3 ms 760 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 504 KB Output is correct
69 Correct 2 ms 632 KB Output is correct
70 Correct 3 ms 760 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 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 2 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 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 508 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 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 2 ms 504 KB Output is correct
50 Correct 4 ms 988 KB Output is correct
51 Correct 4 ms 1016 KB Output is correct
52 Correct 4 ms 888 KB Output is correct
53 Correct 4 ms 888 KB Output is correct
54 Correct 3 ms 760 KB Output is correct
55 Correct 6 ms 1016 KB Output is correct
56 Correct 6 ms 888 KB Output is correct
57 Correct 5 ms 1016 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 6 ms 632 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 532 KB Output is correct
64 Correct 2 ms 424 KB Output is correct
65 Correct 3 ms 760 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 504 KB Output is correct
69 Correct 2 ms 632 KB Output is correct
70 Correct 3 ms 760 KB Output is correct
71 Correct 223 ms 6748 KB Output is correct
72 Correct 120 ms 6160 KB Output is correct
73 Correct 361 ms 6072 KB Output is correct
74 Correct 124 ms 5372 KB Output is correct
75 Correct 181 ms 5240 KB Output is correct
76 Correct 628 ms 7288 KB Output is correct
77 Correct 1557 ms 6136 KB Output is correct
78 Correct 619 ms 6428 KB Output is correct
79 Correct 593 ms 6072 KB Output is correct
80 Correct 2 ms 380 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 253 ms 760 KB Output is correct
83 Correct 1531 ms 1644 KB Output is correct
84 Correct 102 ms 2168 KB Output is correct
85 Correct 45 ms 1016 KB Output is correct
86 Correct 2 ms 632 KB Output is correct
87 Correct 88 ms 2168 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 2 ms 376 KB Output is correct
90 Correct 2 ms 632 KB Output is correct
91 Correct 14 ms 2040 KB Output is correct
92 Correct 51 ms 4600 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 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 2 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 380 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 632 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Correct 3 ms 632 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 508 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 504 KB Output is correct
46 Correct 2 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 2 ms 504 KB Output is correct
50 Correct 4 ms 988 KB Output is correct
51 Correct 4 ms 1016 KB Output is correct
52 Correct 4 ms 888 KB Output is correct
53 Correct 4 ms 888 KB Output is correct
54 Correct 3 ms 760 KB Output is correct
55 Correct 6 ms 1016 KB Output is correct
56 Correct 6 ms 888 KB Output is correct
57 Correct 5 ms 1016 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 6 ms 632 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 532 KB Output is correct
64 Correct 2 ms 424 KB Output is correct
65 Correct 3 ms 760 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 504 KB Output is correct
69 Correct 2 ms 632 KB Output is correct
70 Correct 3 ms 760 KB Output is correct
71 Correct 223 ms 6748 KB Output is correct
72 Correct 120 ms 6160 KB Output is correct
73 Correct 361 ms 6072 KB Output is correct
74 Correct 124 ms 5372 KB Output is correct
75 Correct 181 ms 5240 KB Output is correct
76 Correct 628 ms 7288 KB Output is correct
77 Correct 1557 ms 6136 KB Output is correct
78 Correct 619 ms 6428 KB Output is correct
79 Correct 593 ms 6072 KB Output is correct
80 Correct 2 ms 380 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 253 ms 760 KB Output is correct
83 Correct 1531 ms 1644 KB Output is correct
84 Correct 102 ms 2168 KB Output is correct
85 Correct 45 ms 1016 KB Output is correct
86 Correct 2 ms 632 KB Output is correct
87 Correct 88 ms 2168 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 2 ms 376 KB Output is correct
90 Correct 2 ms 632 KB Output is correct
91 Correct 14 ms 2040 KB Output is correct
92 Correct 51 ms 4600 KB Output is correct
93 Correct 2110 ms 15644 KB Output is correct
94 Correct 715 ms 13792 KB Output is correct
95 Correct 1082 ms 13580 KB Output is correct
96 Correct 916 ms 11944 KB Output is correct
97 Correct 1155 ms 10844 KB Output is correct
98 Correct 3433 ms 15720 KB Output is correct
99 Correct 3701 ms 15604 KB Output is correct
100 Correct 3776 ms 15640 KB Output is correct
101 Execution timed out 5003 ms 6872 KB Time limit exceeded
102 Halted 0 ms 0 KB -