Submission #630183

# Submission time Handle Problem Language Result Execution time Memory
630183 2022-08-15T21:32:50 Z Ooops_sorry Permutation (APIO22_perm) C++17
100 / 100
2 ms 384 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(51);

#define ll long long
#define pb push_back
#define ld long double

vector<int> construct_permutation(long long k)
{
    if (k == 1) {
        return {};
    }
    if (k == 2) {
        return {0};
    }
    for (auto d : {2, 3, 5, 7, 11, 13, 17}) {
        if (k % d == 0 && k > d) {
            vector<int> a = construct_permutation(k / d), b = construct_permutation(d);
            for (int i = 0; i < b.size(); i++) {
                b[i] += a.size();
            }
            for (int i = 0; i < b.size(); i++) {
                a.pb(b[i]);
            }
            return a;
        }
    }
    vector<int> a = construct_permutation(k / 2);
    a.pb(a.size());
    if (k & 1) {
        vector<int> res{a.size()};
        for (auto to : a) {
            res.pb(to);
        }
        swap(a, res);
    }
	return a;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:22:31: 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 < b.size(); i++) {
      |                             ~~^~~~~~~~~~
perm.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             for (int i = 0; i < b.size(); i++) {
      |                             ~~^~~~~~~~~~
perm.cpp:34:31: warning: narrowing conversion of 'a.std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   34 |         vector<int> res{a.size()};
      |                         ~~~~~~^~
perm.cpp:34:31: warning: narrowing conversion of 'a.std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 304 KB Output is correct
12 Correct 2 ms 304 KB Output is correct
13 Correct 2 ms 340 KB Output is correct