forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10632.cpp
119 lines (117 loc) · 1.74 KB
/
10632.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 55;
int n;
int col[Maxn][Maxn];
int dirx[] = {-1, 1, -1, 1};
int diry[] = {-1, 0, 0, 1};
int dir[] = {7, 1, 9, 3};
vector<int> vec;
void dfs(int r, int c)
{
//cout << r << " " << c << endl;
if (r == n && c == n)
{
return;
}
if (r == c)
{
int x = r + 1, y = c + 1;
while (col[r][c] != 2)
{
vec.push_back(3);
vec.push_back(7);
col[x][y]++;
col[x][y] %= 3;
col[r][c]++;
}
if (col[x][y] == 2 && r == n - 1 && c == n - 1)
{
return;
}
vec.push_back(3);
col[x][y]++;
col[x][y] %= 3;
while (x < n)
{
vec.push_back(1);
x++;
col[x][y]++;
col[x][y] %= 3;
}
dfs(n, c + 1);
return;
}
else
{
int x = r - 1, y = c;
while (col[r][c] != 2)
{
vec.push_back(9);
vec.push_back(1);
col[x][y]++;
col[x][y] %= 3;
col[r][c]++;
}
vec.push_back(9);
col[x][y]++;
col[x][y] %= 3;
dfs(x, y);
}
}
int Col[Maxn][Maxn];
int main()
{
while (scanf("%d", &n) != EOF)
{
if (n == 0)
{
break;
}
for (int i = 1; i <= n; ++i)
{
char str[Maxn];
scanf("%s", str + 1);
for (int j = 1; j <= i; ++j)
if (str[j] == 'R')
{
Col[i][j] = col[i][j] = 0;
}
else if (str[j] == 'G')
{
Col[i][j] = col[i][j] = 1;
}
else
{
Col[i][j] = col[i][j] = 2;
}
}
vec.clear();
dfs(n, 1);
if (col[n][n] != 2)
{
vec.clear();
vec.push_back(1);
Col[n][1]++;
Col[n][1] %= 3;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= i; ++j)
{
col[i][j] = Col[i][j];
}
dfs(n, 1);
printf("%d 1\n", n - 1);
}
else
{
printf("%d 1\n", n);
}
assert(col[n][n] == 2);
for (int i = 0; i < vec.size(); ++i)
{
printf("%d", vec[i]);
}
puts("");
}
return 0;
}