-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCOLONY.cpp
85 lines (64 loc) · 1.31 KB
/
COLONY.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// AC, ALGO: Number Theory, Recursion.
/* Some Helpful Links:
http://oeis.org/search?q=0%2C2%2C6%2C150&language=english&go=Search
http://mathworld.wolfram.com/Thue-MorseSequence.html
http://www.wikihow.com/Generate-the-Thue-Morse-Sequence
http://en.wikipedia.org/wiki/Thue%E2%80%93Morse_sequence
*/
// For any clarifications, contact me at: [email protected]
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long i64;
i64 inv;
inline void solve( i64 len, i64 post, i64 year )
{
// printf("len = %lld, post = %lld, year = %lld, inv = %lld\n",len,post,year,inv);
if( len == 2 )
{
i64 ret;
if( post == 1 )
ret = 1;
else
ret = 0;
if( inv & 1 )
{
if( ret == 1 )
ret = 0;
else
ret = 1;
}
// printf("ret = %lld\n",ret);
puts( !ret ? "red" : "blue" );
return;
}
else if( post > len/2 )
solve( len/2, post - len/2, year - 1 );
else
{
inv++;
solve( len/2 ,post ,year - 1 );
}
}
int main()
{
i64 len, post, year, t, store[52];
store[0] = 1;
for( t = 1; t <= 51; t++ )
store[t] = 2 * store[t-1];
// printf("\n") ;
for( t = 1; t--; )
{
scanf("%lld %lld",&year,&post);
if( !year && !post )
{
printf("red\n");
continue;
}
len = store[year];
post++;
inv = 0;
solve( len, post, year );
}
return 0;
}