Submission #161595

# Submission time Handle Problem Language Result Execution time Memory
161595 2019-11-03T08:31:34 Z oolimry Toys (CEOI18_toy) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

int p;
bool comp(int x, int y){
	int xx = 0;
	int yy = 0;
	while(x % p == 0){
		xx++;
		x /= p;
	}
	while(y % p == 0){
		yy++;
		y /= p;
	}
	return xx < yy;
}

vector<vector<int> > adj;
vector<vector<int> > memo;
vector<int> factors;


int main(){
	int n;
	cin >> n;
	
	vector<int> primes;
	for(int i = 1;i <= min(n,100000);i++){
		if(n % i == 0){
			factors.push_back(i);
			factors.push_back(n/i);
		}
	}
	sort(factors.begin(),factors.end());
	factors.erase(unique(factors.begin(),factors.end()),factors.end());
	
	for(int x : factors){
		if(isPrime(x)) primes.push_back(x);
	}
	
	for(int pp : primes){
		p = pp;
		stable_sort(factors.begin(),factors.end(),comp);
	}
	for(int i = 0;i < (int) factors.size();i++){
		vector<int> v;
		adj.push_back(v);
		memo.push_back({});
		//index[factors[i]] = i;
	}
	memo[0].push_back({0});
	for(int i = 0;i < (int) factors.size();i++){
		for(int j = i+1;j < (int) factors.size();j++){
			int x = factors[i];
			int y = factors[j];
			if(y % x == 0){
				int z = y / x;
				if(true){
					adj[j].push_back(i);
					//cout << i << " " << j << "\n";
				}
			}
		}
	}
	vector<int> answer;
	for(int i = 1;i < (int) factors.size();i++){
		for(int j : adj[i]){
			int c = factors[i] / factors[j] - 1;
			for(int v : memo[j]){
				memo[i].push_back(v + c);
			}
		}
		answer = memo[i];
		sort(answer.begin(),answer.end());
		answer.erase(unique(answer.begin(),answer.end()),answer.end());
	}
	
	
	//sort(answer.begin(),answer.end());
	//answer.erase(unique(answer.begin(),answer.end()),answer.end());
	cout << answer.size() << "\n";
	for(int x : answer){
		cout << x << " ";
	}
	
}

Compilation message

toy.cpp: In function 'int main()':
toy.cpp:76:9: warning: unused variable 'z' [-Wunused-variable]
     int z = y / x;
         ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -