Submission #95146

#TimeUsernameProblemLanguageResultExecution timeMemory
95146Retro3014Toys (CEOI18_toy)C++17
100 / 100
2802 ms17140 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;
#define INF 1000000001
typedef long long ll;

int N;
vector<int> d;
vector<int> ans;

int multi(int a, int b){
	ll x = 1;
	while(b--){
		x*=(ll)a;
		x = min(x, (ll)INF);
	}
	return min(x, (ll)INF);
}

int answer;
int now;

void dfs(int x, int y){
	if(x==31){
		if(now==1){
			ans.push_back(answer);
		}
		return;
	}
	for(int i=y; i<d.size(); i++){
		if(multi(d[i], 31-x)>now) return;
		if(now%d[i]!=0)	continue;
		now/=d[i];
		answer+=d[i]-1;
		dfs(x+1, i);
		answer-=d[i]-1;
		now*=d[i];
	}
}

int main(){
	scanf("%d", &N);
	for(int i=1; i*i<=N; i++){
		if(N%i==0){
			d.push_back(i); 
			if(i*i!=N)	d.push_back(N/i);
		}
	}
	sort(d.begin(), d.end());
	now = N;
	dfs(1, 0);
	sort(ans.begin(), ans.end());
	for(int i=ans.size()-1; i>0; i--){
		if(ans[i]==ans[i-1])	ans[i] = INF;
	}
	sort(ans.begin(), ans.end());
	while(!ans.empty() && ans.back()==INF)	ans.pop_back();
	printf("%d\n", ans.size());
	for(int i=0; i<ans.size(); i++){
		printf("%d ", ans[i]);
	}
	return 0;
}

Compilation message (stderr)

toy.cpp: In function 'void dfs(int, int)':
toy.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=y; i<d.size(); i++){
               ~^~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:61:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", ans.size());
                 ~~~~~~~~~~^
toy.cpp:62:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<ans.size(); i++){
               ~^~~~~~~~~~~
toy.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...