# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
493252 |
2021-12-10T13:57:51 Z |
blue |
Toys (CEOI18_toy) |
C++17 |
|
2 ms |
4300 KB |
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define sz(x) (int(x.size()))
using vi = vector<int>;
using ll = long long;
// 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);
vector<int> factors[40'000];
vector<int> factors2[40'000];
vector<int>& get_res(long long u)
{
if(u*u <= n) return res[u];
else return res2[n/u];
}
vector<int>& get_factors(long long u)
{
if(u*u <= n) return factors[u];
else return factors2[n/u];
}
int& get_solved(long long u)
{
if(u*u <= n) return solved[u];
else return solved2[n/u];
}
ll opc = 0;
void solve(long long i)
{
vi ans(1, i-1);
for(ll j: get_factors(i))
{
// cerr << "j = " << j << '\n';
if(j >= i || j*j > i) break;
// cerr << i << " -> " << j << '\n';
long long u = j;
long long v = i/j;
for(int a: get_res(u))
{
for(int b: get_res(v))
{
opc++;
// if(b > a) break;
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';
get_res(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(i*i > n) break;
if(n % i == 0)
{
sf.push_back(i);
sf.push_back(n/i);
}
}
// for(int i = 2; i <= n; i++)
// {
// // cerr << i << " " << n%i << ' ' << int(n%i == 0) << '\n';
// if(n % i == 0)
// sf.push_back(i);
// }
sf.push_back(n);
sort(sf.begin(), sf.end());
sf.erase(unique(sf.begin(), sf.end()), sf.end());
// for(int q: sf) cerr << q << ' ';
// cerr << '\n';
int fact_pairs = 0;
for(int a: sf)
for(int b: sf)
if(a < b && b%a==0)
get_factors(b).push_back(a);
// for(int a: sf)
// for(int b: sf)
// if(a < b && b%a==0)
// fact_pairs++;
// cerr << "factors = " << sz(sf) << '\n';
// cerr << "factor pairs = " << fact_pairs << '\n';
for(int i: sf) solve(i);
vi ans = get_res(n);
// cerr << "sf init = " ;
// for(int q: sf) cerr << q << " ";
// cerr << "\n";
cout << sz(ans) << '\n';
// for(int r: ans) cout << r << ' ';
cout << '\n';
// cout << opc << '\n';
}
Compilation message
toy.cpp: In function 'int main()':
toy.cpp:122:9: warning: unused variable 'fact_pairs' [-Wunused-variable]
122 | int fact_pairs = 0;
| ^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4300 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4300 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4300 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4300 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4300 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4300 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |