Submission #579807

# Submission time Handle Problem Language Result Execution time Memory
579807 2022-06-19T22:41:06 Z peuch Permutation (APIO22_perm) C++17
100 / 100
7 ms 1748 KB
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
const long long magic = 1000;

unordered_map<long long, vector<int> > dp;

std::vector<int> construct_permutation(long long k)
{
	if(k == 1) return vector<int> (0);
	if(k == 2) return vector<int> (1);
	if(!dp[k].empty()) return dp[k];
//	printf("%lld %lld\n", k, (long long)sqrt(k) + 1);
//	printf("%lld\n", k);
	for(long long i = 2; i * i <= min(k, magic); i++){
//		printf("%lld\n", i);
		if(!dp[k].empty()) break;
		if(k % i != 0) continue;
//		printf("Testing dividing %lld by %d\n", k, i);
		vector<int> aux1 = construct_permutation(i);
		vector<int> aux2 = construct_permutation(k / i);
		for(int i = 0; i < aux1.size(); i++)
			dp[k].push_back(aux1[i]);
		for(int i = 0; i < aux2.size(); i++)
			dp[k].push_back(aux2[i] + aux1.size());
	}
//	printf("Ok\n");
	if(dp[k].empty()){
		dp[k] = construct_permutation(k - 1);
		dp[k].insert(dp[k].begin(), dp[k].size());
	}
//	printf("%lld\n", k);
	return dp[k];
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for(int i = 0; i < aux1.size(); i++)
      |                  ~~^~~~~~~~~~~~~
perm.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i = 0; i < aux2.size(); i++)
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 7 ms 1748 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 7 ms 1748 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 7 ms 1492 KB Output is correct