-
Notifications
You must be signed in to change notification settings - Fork 0
/
coloringFlag.cpp
131 lines (115 loc) · 1.99 KB
/
coloringFlag.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
120
121
122
123
124
125
126
127
128
129
130
#include<bits/stdc++.h>
using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vl vector<ll>
#define vi vector<int>
#define lb lower_bound
#define ub upper_bound
// vector<vector<int>> vec( n , vector<int> (m, 0));
// priority_queue<pi, vector<pi>, greater<pi>>q;
typedef int64_t ll;
#define pi pair<ll, int>
// https://codeforces.com/contest/1534/problem/A
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool dfs(vector<vector<char>>&mat, int i, int j, int n, int m)
{
for (int k = 0; k < 4; k++)
{
int i1 = i + dx[k];
int j1 = j + dy[k];
if ((i1 >= 0 && i1 < n) && (j1 >= 0 && j1 < m))
{
if (mat[i1][j1] != '.')
{
if (mat[i][j] == mat[i1][j1])
{
return 0;
}
}
else
{
if (mat[i][j] == 'R')
{
mat[i1][j1] = 'W';
}
else
{
mat[i1][j1] = 'R';
}
if (!dfs(mat, i1, j1, n, m))
{
return 0;
}
}
}
}
return 1;
}
void solve()
{
int n, m;
cin >> n >> m;
vector<vector<char>> mat( n , vector<char> (m, '0'));
bool flag = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
cin >> mat[i][j];
if (mat[i][j] != '.')
{
flag = 1;
}
/* code */
}
/* code */
}
if (flag == 0)
{
mat[0][0] = 'R';
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if (mat[i][j] != '.')
{
if (!dfs(mat, i, j, n, m))
{
cout << "NO" << endl;
return;
}
}
}
// cout << endl;
}
cout << "YES" << endl;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
cout << mat[i][j] << "" ;
}
cout << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}