Submission #572922

# Submission time Handle Problem Language Result Execution time Memory
572922 2022-06-05T13:42:07 Z moday_morning Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k)
{
    // 90 balls
    vector <int> ans;
    vector <int> bytes;
    for (int i = 63; i >= 1; i--) {
        if (k & (1ll << i)) {
            bytes.push_back(i);
        }
    }
    int mx = bytes[0];
    for (int i = 0; i < mx; i++) {
        ans.push_back(i);
    }
    
//    cout << "bytes" << endl;
//    for (int el : bytes) {
//        cout << el << " ";
//    }cout << endl;
//
    for (int i = 1; i < bytes.size(); i++) {
        int cur_bit = bytes[i];
        for (int j = 0; j < ans.size(); j++) {
            if (ans[j] >= cur_bit) {
                ans[j]++;
            }
        }
        ans.push_back(cur_bit);
    }
    if (k % 2) {
        for (int j = 0; j < ans.size(); j++) {
            ans[j]++;
        }
        ans.push_back(0);
    }
    return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:24:23: 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 = 1; i < bytes.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
perm.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int j = 0; j < ans.size(); j++) {
      |                         ~~^~~~~~~~~~~~
perm.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int j = 0; j < ans.size(); j++) {
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 212 KB Output is correct
5 Partially correct 1 ms 340 KB Partially correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Partially correct 2 ms 340 KB Partially correct
9 Correct 2 ms 340 KB Output is correct
10 Partially correct 2 ms 304 KB Partially correct
11 Partially correct 2 ms 340 KB Partially correct
12 Partially correct 2 ms 340 KB Partially correct
13 Partially correct 2 ms 340 KB Partially correct