-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZ.cpp
More file actions
46 lines (36 loc) · 883 Bytes
/
Z.cpp
File metadata and controls
46 lines (36 loc) · 883 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, r, c;
cin >> n >> r >> c;
vector<int> lookupPow2(n+1, 1);
for (int i=1; i<=n; ++i)
{
lookupPow2[i] *= lookupPow2[i-1] * 2;
}
vector<int> adress;
for (int i = 1; i <= n ; ++i)
{
bool isUp = (r % lookupPow2[i]) < lookupPow2[i-1];
bool isLeft = (c % lookupPow2[i]) < lookupPow2[i-1];
int location = 0;
if (isUp && isLeft)
location = 0;
if (isUp && !isLeft)
location = 1;
if (!isUp && isLeft)
location = 2;
if (!isUp && !isLeft)
location = 3;
adress.push_back(location);
}
int answer = 0;
for (int i=0; i<=n; ++i)
{
answer += lookupPow2[i] * lookupPow2[i] * adress[i];
}
cout << answer << endl;
return 0;
}