Submission #278092

# Submission time Handle Problem Language Result Execution time Memory
278092 2020-08-21T10:08:51 Z Retro3014 Toys (CEOI18_toy) C++17
0 / 100
5000 ms 256 KB
#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], 29-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

toy.cpp: In function 'void dfs(int, int)':
toy.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i=y; i<d.size(); i++){
      |               ~^~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:61:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   61 |  printf("%d\n", ans.size());
      |          ~^     ~~~~~~~~~~
      |           |             |
      |           int           std::vector<int>::size_type {aka long unsigned int}
      |          %ld
toy.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  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]
   45 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 5044 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5044 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5044 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5044 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5044 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -