-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathccc08s5.cpp
More file actions
61 lines (61 loc) · 1.47 KB
/
Copy pathccc08s5.cpp
File metadata and controls
61 lines (61 loc) · 1.47 KB
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
// Ivan Carvalho
// Solution to https://dmoj.ca/problem/ccc08s5
#include <cstdio>
#include <cstring>
#define MAXN 31
int dp[MAXN][MAXN][MAXN][MAXN];
int solve(int a, int b, int c, int d) {
if (dp[a][b][c][d] != -1) return dp[a][b][c][d];
int possiveis = 0, vencedoras = 0;
if (a >= 2 && b >= 1 && d >= 2) {
possiveis++;
if (solve(a - 2, b - 1, c, d - 2) == 1) {
vencedoras++;
}
}
if (a >= 1 && b >= 1 && c >= 1 && d >= 1) {
possiveis++;
if (solve(a - 1, b - 1, c - 1, d - 1) == 1) {
vencedoras++;
}
}
if (c >= 2 && d >= 1) {
possiveis++;
if (solve(a, b, c - 2, d - 1) == 1) {
vencedoras++;
}
}
if (b >= 3) {
possiveis++;
if (solve(a, b - 3, c, d) == 1) {
vencedoras++;
}
}
if (a >= 1 && d >= 1) {
possiveis++;
if (solve(a - 1, b, c, d - 1) == 1) {
vencedoras++;
}
}
if (possiveis == vencedoras) return dp[a][b][c][d] = 0;
return dp[a][b][c][d] = 1;
}
int main() {
int TC;
scanf("%d", &TC);
memset(dp, -1, sizeof(dp));
dp[2][1][0][2] = 1;
dp[1][1][1][1] = 1;
dp[0][0][2][1] = 1;
dp[0][3][0][0] = 1;
dp[1][0][0][1] = 1;
while (TC--) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
if (solve(a, b, c, d))
printf("Patrick\n");
else
printf("Roland\n");
}
return 0;
}