#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
long long prime[5]={2, 3, 5, 7, 11};
vector<int> construct_permutation(long long k, long long PRIME)
{
for (long long u=0; u<=PRIME; u++)
{
long long v=prime[u];
if (k%v==0)
{
long long cnt=0;
while (k%v==0)
{
k/=v;
cnt++;
}
if (k==1)
{
vector<int> res;
for (long long i=0; i<cnt; i++)
for (long long j=v-2; j>=0; j--)
res.push_back(i*(v-1)+j);
return res;
}
vector<int> res=construct_permutation(k, PRIME);
int sz=res.size();
for (long long j=0; j<cnt; j++)
for (long long m=v-2; m>=0; m--)
res.push_back(j*(v-1)+m+sz);
return res;
}
}
for (long long i=2, m=1; ; i*=2, m++)
{
if (i<k && i*2>k)
{
vector<int> res=construct_permutation(k-i+1, PRIME);
for (long long j=0; j<res.size(); j++)
res[j]+=m;
for (long long j=0; j<m; j++)
res.push_back(j);
return res;
}
}
}
vector<int> construct_permutation(long long k)
{
vector<int> vec[5];
long long ind, mn=1e9;
for (long long i=0; i<5; i++)
{
vec[i]=construct_permutation(k, i);
if (mn>vec[i].size())
{
mn=vec[i].size();
ind=i;
}
}
return vec[ind];
}
Compilation message
perm.cpp: In function 'std::vector<int> construct_permutation(long long int, long long int)':
perm.cpp:39:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (long long j=0; j<res.size(); j++)
| ~^~~~~~~~~~~
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:54:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if (mn>vec[i].size())
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Partially correct |
1 ms |
340 KB |
Partially correct |
5 |
Partially correct |
3 ms |
340 KB |
Partially correct |
6 |
Partially correct |
3 ms |
340 KB |
Partially correct |
7 |
Partially correct |
4 ms |
468 KB |
Partially correct |
8 |
Partially correct |
5 ms |
488 KB |
Partially correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Partially correct |
5 ms |
468 KB |
Partially correct |
11 |
Partially correct |
5 ms |
484 KB |
Partially correct |
12 |
Partially correct |
4 ms |
468 KB |
Partially correct |
13 |
Partially correct |
4 ms |
468 KB |
Partially correct |