#include <bits/stdc++.h>
// author : Pluton
#define OPT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int ll
#define ll long long
#define pb push_back
#define arr array
#define fi first
#define se second
#define rep(i,j,k) for(int i = j; i <= k; ++i)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
using namespace std;
const int INF = 1e18;
struct BIT
{
int n;
vector<int> ft;
void init(int N)
{
n = N + 5;
ft.assign(n + 5, 0);
}
void add(int pos, int val)
{
for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] += val;
}
int get(int pos, int res = 0)
{
for (pos = pos + 1; pos > 0; pos -= pos & -pos) res += ft[pos];
return res;
}
};
int ans =0 ;
int f(int n, int k, int val)
{
int v = 0;
if(n == 0)
return 0;
int a = 0;
if(n < 64)
{
int op = pow(2, n - 1);
if(k >= op)
{
v += pow(2, val);
f(n - 1, k - op, val + 1);
ans += v;
return 0;
}
}
f(n - 1, k, val + 1);
ans += val;
return 0;
}
void _()
{
int n, k;
cin >> n >> k;
--k;
f(n, k, 0);
cout << ans;
}
signed main()
{
OPT
int tc = 1;
while(tc--)
{
_();
}
}
Compilation message
rack.cpp: In function 'long long int f(long long int, long long int, long long int)':
rack.cpp:41:9: warning: unused variable 'a' [-Wunused-variable]
41 | int a = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |