-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC_115_D.cpp
58 lines (48 loc) · 900 Bytes
/
ABC_115_D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
long long totalLength[51];
long long pattyLength[51];
void getLength(int level) {
if (level == 0)
{
totalLength[level] = 1;
pattyLength[level] = 1;
return;
}
getLength(level - 1);
totalLength[level] = totalLength[level - 1] * 2 + 3;
pattyLength[level] = pattyLength[level - 1] * 2 + 1;
}
long long solve(int level, long long x) {
if (level == 0)
{
return 1;
}
if (x <= 1)
{
return 0;
}
else if (x <= 1 + totalLength[level - 1])
{
return solve(level - 1, x - 1);
}
else if (x == 1 + totalLength[level - 1] + 1)
{
return pattyLength[level - 1] + 1;
}
else if (x < totalLength[level])
{
return pattyLength[level - 1] + 1 + solve(level - 1, x - totalLength[level - 1] - 2);
}
else
{
return pattyLength[level];
}
}
int main() {
int n;
long long x;
cin >> n >> x;
getLength(n);
cout << solve(n, x) << endl;
}