#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
ll modd(ll x, ll n){while(x < 0){x += n;}return (x % n);} // modulo for negative numbers
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vdd vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int msb(ll n){
int i = 0;
int last = 0;
while(n > 0){
if(n&1)last = i;
n/=2;
i++;
}
return last;
}
vector<int> construct_permutation(long long k){
int i = 0;
vi res;
while(k > 0){
ll wanted = k;
if(i != 0)wanted++;
int found = msb(wanted);
cout << k << " " << found << endl;
res.pb(found);
k -= (1 << found);
if(i !=0)k++;
i++;
}
int c = 0;
for(int i = 0; i < res.size();i++){
c += res[i];
}
vi v;
for(int i = 0; i < res.size();i++){
int x = c - res[i];
for(int j = x; j< c;j++){
v.pb(j);
}
c = x;
}
return v;
}
Compilation message
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i = 0; i < res.size();i++){
| ~~^~~~~~~~~~~~
perm.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < res.size();i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
secret mismatch |
2 |
Halted |
0 ms |
0 KB |
- |