Submission #581674

# Submission time Handle Problem Language Result Execution time Memory
581674 2022-06-23T02:52:08 Z HunterXD Toys (CEOI18_toy) C++17
100 / 100
2416 ms 86724 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector <char> vc;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef pair<ll,ll> pl;
typedef double dou;
typedef vector<pl> vpl;
typedef unsigned long long ull;
typedef uint64_t i64;
typedef vector<ull> vull;

#define f first 
#define s second 
#define pb push_back 
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define ts to_string
#define lb lower_bound 
#define ub upper_bound
#define yes cout<<'Y'<<'E'<<'S'<<endl
#define no cout<<'N'<<'O'<<endl
#define nd "\n"

void setIO(string name=""){ios_base::sync_with_stdio(0);cin.tie(0);if(sz(name)){freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);}}
 
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll mcm(ll a, ll b) {return (a * b) / gcd(a, b);}
bool prime(ll n) {for(int i=2; i<=sqrt(n); i++) if(n%i==0) return false; return true;}
struct compii{bool operator()(const ii &a, const ii &b){if(a.f==a.s)return a.s<b.s;return a.f>b.f;}};
bool comp(int a, int b) {return a>b;}
ll binpow(ll n, ll x){ll ans=1; while(x){if(x&1){ans*=n;}n*=n; x>>=1;} return ans;}

namespace operators {
template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2>& x){in >> x.first >> x.second;return in;}
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> x){out << x.first << " " << x.second;return out;}
template<typename T1>istream& operator>>(istream& in, vector<T1>& x) {for (auto& i : x) in >> i;return in;}
template<typename T1>ostream& operator<<(ostream& out, vector<T1>& x) {for (auto& i : x) out << i << " ";return out;}
template<typename T1, typename T2>ostream& operator<<(ostream& out, vector<pair <T1,T2>>& x) {for (auto& i : x) out << i.f << " "<<i.s;return out;}
template<typename T1, typename T2>istream& operator>>(istream& in, vector<pair <T1,T2>>& x) {for (auto& i : x) in >> i.f >>i.s;return in;}
}

using namespace operators;

int dx[]= {1,0,-1,0};
int dy[]= {0,1,0,-1};

const int pmod = 998244353;
const int mod = 1e9+7;
const ll inf=1e18;

ll sum(ll a, ll b){
  return (( (a+mod) %mod) + ((b+mod)%mod))%mod;
}

ll multi(ll a, ll b){
  return (((a+mod) %mod) * ((b+mod)%mod))%mod;
}

///

vector<ll> divi;
ll llevo = 1;

vector<pl> divide(ll n){

  vector<pl> res;
  ll counter = 0;
  while(n%2 == 0){
    n/= 2;
    counter++;
  }
  if(counter) res.pb({2, counter});

  for(ll i = 3; i*i <= n; i+= 2){
    counter = 0;
    while(n%i == 0){
      n/= i;
      counter++;
    }
    if(counter) res.pb({i, counter});
  }

  if(n != 1) res.pb({n, 1});
  return res;
}

void calc_div(vector<pl> &me, ll pos){
  if(pos == me.size()){
    divi.pb(llevo);
    return;
  }

  ll c = me[pos].s;
  ll temp = 1;
  for(ll i = 0; i <= c; i++){
    llevo*= temp;
    calc_div(me, pos+1);
    llevo/= temp;
    temp*= me[pos].f;
  }
}

void solve(){

  ll n;
  cin >> n;

  vector<pl> me = divide(n);
  llevo = 1;
  calc_div(me, 0);

  sort(all(divi));
  
  ll m = divi.size(), temp;
  vector< set<ll> > res(m, set<ll>());
  
  for(ll i = 0; i < m; i++){
    for(ll i2 = 0; i2 < i; i2++){
      if(divi[i]%divi[i2]) continue;
      temp = divi[i]/divi[i2];
      for(auto v: res[i2]){
        res[i].insert(v + temp-1);   
      }
    }
    res[i].insert(divi[i]-1);
  }

  cout << res[m-1].size() << endl;
  for(auto v: res[m-1]){
    cout << v << " ";
  }
  cout << endl;
}

int main (){
  setIO("");
  int t = 1;
  //cin >> t;
  while(t-->0) solve();
  return 0;
}

Compilation message

toy.cpp: In function 'void calc_div(std::vector<std::pair<long long int, long long int> >&, ll)':
toy.cpp:98:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |   if(pos == me.size()){
      |      ~~~~^~~~~~~~~~~~
toy.cpp: In function 'void setIO(std::string)':
toy.cpp:34:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 | void setIO(string name=""){ios_base::sync_with_stdio(0);cin.tie(0);if(sz(name)){freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);}}
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp:34:128: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 | void setIO(string name=""){ios_base::sync_with_stdio(0);cin.tie(0);if(sz(name)){freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);}}
      |                                                                                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 316 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 316 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 3 ms 576 KB Output is correct
51 Correct 2 ms 576 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 4 ms 596 KB Output is correct
56 Correct 4 ms 656 KB Output is correct
57 Correct 4 ms 596 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 1 ms 320 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 320 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 316 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 3 ms 576 KB Output is correct
51 Correct 2 ms 576 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 4 ms 596 KB Output is correct
56 Correct 4 ms 656 KB Output is correct
57 Correct 4 ms 596 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 1 ms 320 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 320 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 307 ms 18484 KB Output is correct
72 Correct 217 ms 14132 KB Output is correct
73 Correct 302 ms 16440 KB Output is correct
74 Correct 163 ms 11040 KB Output is correct
75 Correct 186 ms 11768 KB Output is correct
76 Correct 507 ms 24816 KB Output is correct
77 Correct 435 ms 21908 KB Output is correct
78 Correct 398 ms 20584 KB Output is correct
79 Correct 377 ms 20016 KB Output is correct
80 Correct 1 ms 224 KB Output is correct
81 Correct 1 ms 224 KB Output is correct
82 Correct 3 ms 608 KB Output is correct
83 Correct 38 ms 3684 KB Output is correct
84 Correct 48 ms 4356 KB Output is correct
85 Correct 11 ms 1520 KB Output is correct
86 Correct 1 ms 352 KB Output is correct
87 Correct 61 ms 4956 KB Output is correct
88 Correct 1 ms 224 KB Output is correct
89 Correct 1 ms 224 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 21 ms 2016 KB Output is correct
92 Correct 69 ms 6468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 316 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 3 ms 576 KB Output is correct
51 Correct 2 ms 576 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 4 ms 596 KB Output is correct
56 Correct 4 ms 656 KB Output is correct
57 Correct 4 ms 596 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 1 ms 320 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 320 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 307 ms 18484 KB Output is correct
72 Correct 217 ms 14132 KB Output is correct
73 Correct 302 ms 16440 KB Output is correct
74 Correct 163 ms 11040 KB Output is correct
75 Correct 186 ms 11768 KB Output is correct
76 Correct 507 ms 24816 KB Output is correct
77 Correct 435 ms 21908 KB Output is correct
78 Correct 398 ms 20584 KB Output is correct
79 Correct 377 ms 20016 KB Output is correct
80 Correct 1 ms 224 KB Output is correct
81 Correct 1 ms 224 KB Output is correct
82 Correct 3 ms 608 KB Output is correct
83 Correct 38 ms 3684 KB Output is correct
84 Correct 48 ms 4356 KB Output is correct
85 Correct 11 ms 1520 KB Output is correct
86 Correct 1 ms 352 KB Output is correct
87 Correct 61 ms 4956 KB Output is correct
88 Correct 1 ms 224 KB Output is correct
89 Correct 1 ms 224 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 21 ms 2016 KB Output is correct
92 Correct 69 ms 6468 KB Output is correct
93 Correct 1946 ms 77224 KB Output is correct
94 Correct 1050 ms 52024 KB Output is correct
95 Correct 1215 ms 54524 KB Output is correct
96 Correct 1088 ms 48768 KB Output is correct
97 Correct 966 ms 44380 KB Output is correct
98 Correct 2262 ms 85184 KB Output is correct
99 Correct 2416 ms 86724 KB Output is correct
100 Correct 2189 ms 83340 KB Output is correct
101 Correct 2001 ms 77076 KB Output is correct
102 Correct 1756 ms 69340 KB Output is correct
103 Correct 1454 ms 62144 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 1 ms 320 KB Output is correct
106 Correct 5 ms 852 KB Output is correct
107 Correct 143 ms 9528 KB Output is correct
108 Correct 397 ms 20336 KB Output is correct
109 Correct 27 ms 3156 KB Output is correct
110 Correct 1 ms 212 KB Output is correct
111 Correct 186 ms 12096 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 6 ms 852 KB Output is correct
115 Correct 1 ms 212 KB Output is correct
116 Correct 10 ms 1588 KB Output is correct
117 Correct 340 ms 24484 KB Output is correct