Submission #956109

# Submission time Handle Problem Language Result Execution time Memory
956109 2024-04-01T05:46:42 Z Otalp Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 348 KB
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back


vector<int> construct_permutation(ll k)
{
    vector<int> ans;
    int fbit = 0;
    for(int i=60; i>=0; i--){
        if((k & (1ll << i))){
            fbit = i;
            break;
        }
    }
    vector<int> h;
    for(int i=fbit; i>=0; i--){
        if((k & (1ll << i))){
            int cnt = 0;
            for(int j=i-1; j>=0; j--){
                cnt++;
                if((k & (1ll << j))) break;
            }
            h.pb(cnt);
            //cout<<k<<' '
        }
    }
    for(int i=0; i<h[0]; i++){
        ans.pb(i);
    }
    int l=0, r=h[0]-1;
    for(int i=1; i<h.size(); i++){
        ans.pb(--l);
        for(int j=0; j<h[i]; j++){
            ans.pb(++r);
        }
    }
    for(int i=0; i<ans.size(); i++){
        ans[i] -= l;
    }
    for(int i=0; i<ans.size(); i++){
        //cout<<ans[i]<<' ';
    }
    return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=1; i<h.size(); i++){
      |                  ~^~~~~~~~~
perm.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0; i<ans.size(); i++){
      |                  ~^~~~~~~~~~~
perm.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0; i<ans.size(); i++){
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Partially correct 1 ms 348 KB Partially correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Partially correct 1 ms 348 KB Partially correct
9 Correct 1 ms 348 KB Output is correct
10 Partially correct 1 ms 344 KB Partially correct
11 Partially correct 2 ms 348 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct