답안 #237710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237710 2020-06-08T12:10:44 Z Nucleist Toys (CEOI18_toy) C++14
100 / 100
1383 ms 45308 KB
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
unordered_map<ll,ve>kol;
unordered_map<ll,vector<ll>>dp;
vector<ll> rec(ll n){
  if(dp.find(n)!=dp.end())return dp[n];
  vector<ll> ans;
  if(kol.find(n)==kol.end()){
    ve divi;
    for (ll i = 2; i <= sqrt(n); ++i)
    {
      if(!(n%i)){
        divi.pb(i);
        divi.pb(n/i);
        vector<ll> curi=rec(n/i);
        for(auto it:curi)ans.pb(it+(i-1));
        vector<ll> curi1=rec(i);
        for(auto it:curi1)ans.pb(it+(n/i-1));
      }
    }
    //sort(all(divi));
    kol[n]=divi;
  }
  else{
    for(auto it:kol[n]){
      vector<ll> cur=rec(n/it);
      for(auto it1:cur)ans.pb(it1+it-1);
    }
  }
  ans.pb(n-1);
  sort(all(ans));
  ll last=-1;
  ve raj;
  for (int i = 0; i < ans.size(); ++i)
  {
    if(ans[i]!=last){
      last=ans[i];
      raj.pb(ans[i]);
    }
  }
  return dp[n]=raj;
}
int main()
{
  flash;
  ll n;
  cin>>n;
  vector<ll>ans=rec(n);
  cout<<ans.size()<<'\n';
  for (auto it:ans)
  {
    cout<<it<<" ";
  }
  return 0;
}
//code the AC sol !
// BS/queue/map

Compilation message

toy.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
toy.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
toy.cpp: In function 'std::vector<long long int> rec(long long int)':
toy.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ans.size(); ++i)
                   ~~^~~~~~~~~~~~
toy.cpp: In function 'void setIO(std::__cxx11::string)':
toy.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 7 ms 512 KB Output is correct
51 Correct 6 ms 512 KB Output is correct
52 Correct 7 ms 512 KB Output is correct
53 Correct 6 ms 512 KB Output is correct
54 Correct 6 ms 384 KB Output is correct
55 Correct 7 ms 512 KB Output is correct
56 Correct 7 ms 512 KB Output is correct
57 Correct 7 ms 512 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 6 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 7 ms 512 KB Output is correct
66 Correct 4 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 4 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 7 ms 512 KB Output is correct
51 Correct 6 ms 512 KB Output is correct
52 Correct 7 ms 512 KB Output is correct
53 Correct 6 ms 512 KB Output is correct
54 Correct 6 ms 384 KB Output is correct
55 Correct 7 ms 512 KB Output is correct
56 Correct 7 ms 512 KB Output is correct
57 Correct 7 ms 512 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 6 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 7 ms 512 KB Output is correct
66 Correct 4 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 4 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 216 ms 10388 KB Output is correct
72 Correct 153 ms 8992 KB Output is correct
73 Correct 204 ms 9832 KB Output is correct
74 Correct 118 ms 5876 KB Output is correct
75 Correct 133 ms 6252 KB Output is correct
76 Correct 331 ms 12984 KB Output is correct
77 Correct 300 ms 11484 KB Output is correct
78 Correct 261 ms 11364 KB Output is correct
79 Correct 264 ms 11260 KB Output is correct
80 Correct 5 ms 384 KB Output is correct
81 Correct 5 ms 384 KB Output is correct
82 Correct 7 ms 512 KB Output is correct
83 Correct 34 ms 2084 KB Output is correct
84 Correct 43 ms 2624 KB Output is correct
85 Correct 13 ms 988 KB Output is correct
86 Correct 5 ms 384 KB Output is correct
87 Correct 45 ms 2972 KB Output is correct
88 Correct 5 ms 384 KB Output is correct
89 Correct 5 ms 384 KB Output is correct
90 Correct 5 ms 384 KB Output is correct
91 Correct 17 ms 1156 KB Output is correct
92 Correct 55 ms 3564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 7 ms 512 KB Output is correct
51 Correct 6 ms 512 KB Output is correct
52 Correct 7 ms 512 KB Output is correct
53 Correct 6 ms 512 KB Output is correct
54 Correct 6 ms 384 KB Output is correct
55 Correct 7 ms 512 KB Output is correct
56 Correct 7 ms 512 KB Output is correct
57 Correct 7 ms 512 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 6 ms 384 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 5 ms 384 KB Output is correct
65 Correct 7 ms 512 KB Output is correct
66 Correct 4 ms 384 KB Output is correct
67 Correct 5 ms 384 KB Output is correct
68 Correct 4 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 216 ms 10388 KB Output is correct
72 Correct 153 ms 8992 KB Output is correct
73 Correct 204 ms 9832 KB Output is correct
74 Correct 118 ms 5876 KB Output is correct
75 Correct 133 ms 6252 KB Output is correct
76 Correct 331 ms 12984 KB Output is correct
77 Correct 300 ms 11484 KB Output is correct
78 Correct 261 ms 11364 KB Output is correct
79 Correct 264 ms 11260 KB Output is correct
80 Correct 5 ms 384 KB Output is correct
81 Correct 5 ms 384 KB Output is correct
82 Correct 7 ms 512 KB Output is correct
83 Correct 34 ms 2084 KB Output is correct
84 Correct 43 ms 2624 KB Output is correct
85 Correct 13 ms 988 KB Output is correct
86 Correct 5 ms 384 KB Output is correct
87 Correct 45 ms 2972 KB Output is correct
88 Correct 5 ms 384 KB Output is correct
89 Correct 5 ms 384 KB Output is correct
90 Correct 5 ms 384 KB Output is correct
91 Correct 17 ms 1156 KB Output is correct
92 Correct 55 ms 3564 KB Output is correct
93 Correct 1142 ms 41260 KB Output is correct
94 Correct 639 ms 25400 KB Output is correct
95 Correct 744 ms 33812 KB Output is correct
96 Correct 648 ms 24380 KB Output is correct
97 Correct 614 ms 23164 KB Output is correct
98 Correct 1306 ms 44448 KB Output is correct
99 Correct 1383 ms 44628 KB Output is correct
100 Correct 1268 ms 45308 KB Output is correct
101 Correct 1207 ms 43604 KB Output is correct
102 Correct 1081 ms 38760 KB Output is correct
103 Correct 858 ms 37240 KB Output is correct
104 Correct 5 ms 384 KB Output is correct
105 Correct 5 ms 384 KB Output is correct
106 Correct 8 ms 680 KB Output is correct
107 Correct 100 ms 5528 KB Output is correct
108 Correct 233 ms 11240 KB Output is correct
109 Correct 26 ms 1852 KB Output is correct
110 Correct 5 ms 384 KB Output is correct
111 Correct 122 ms 6256 KB Output is correct
112 Correct 5 ms 384 KB Output is correct
113 Correct 5 ms 384 KB Output is correct
114 Correct 10 ms 768 KB Output is correct
115 Correct 5 ms 384 KB Output is correct
116 Correct 14 ms 1008 KB Output is correct
117 Correct 239 ms 12616 KB Output is correct