#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 12, MOD = 998244353;
char a[N][N];
int n, m, res = 0, res1 = 0, v[N][N], it = 1, h[N][N], dp[N * N][2];
vector<int> g[N * N];
void add(int x, int y) {
g[x].push_back(y);
g[y].push_back(x);
}
bool vis[N * N];
void dfs(int v, int pr = -1) {
vis[v] = 1;
dp[v][1] = 1;
for(int to:g[v]) {
if(to == pr || vis[to]) continue;
dfs(to, v);
dp[v][0] += max(dp[to][0], dp[to][1]);
dp[v][1] += dp[to][0];
}
}
void test() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == 'G' && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
h[i][j - 1] = it++;
}
if(a[i][j] == 'G' && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
v[i - 1][j] = it++;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == 'G' && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
if(v[i][j - 1]) {
add(v[i][j - 1], h[i][j - 1]);
}
if(v[i - 1][j]) {
add(v[i - 1][j], h[i][j - 1]);
}
if(v[i - 2][j + 1]) {
add(v[i - 2][j + 1], h[i][j - 1]);
}
}
if(a[i][j] == 'G' && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
if(h[i - 1][j]) {
add(v[i - 1][j], h[i - 1][j]);
}
if(h[i][j - 1]) {
add(v[i - 1][j], h[i][j - 1]);
}
if(h[i + 1][j - 2]) {
add(v[i - 1][j], h[i + 1][j - 2]);
}
}
}
}
for(int i = 1; i < it; i++) {
sort(g[i].begin(), g[i].end());
g[i].resize(unique(g[i].begin(), g[i].end()) - g[i].begin());
}
for(int i = 1; i < it; i++) {
if(!vis[i]) {
dfs(i);
res += max(dp[i][0], dp[i][1]);
}
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
217936 KB |
Output is correct |
2 |
Correct |
35 ms |
217812 KB |
Output is correct |
3 |
Correct |
35 ms |
218104 KB |
Output is correct |
4 |
Correct |
35 ms |
217936 KB |
Output is correct |
5 |
Correct |
36 ms |
217936 KB |
Output is correct |
6 |
Correct |
39 ms |
222032 KB |
Output is correct |
7 |
Correct |
35 ms |
222020 KB |
Output is correct |
8 |
Correct |
35 ms |
222032 KB |
Output is correct |
9 |
Correct |
38 ms |
222032 KB |
Output is correct |
10 |
Correct |
37 ms |
220028 KB |
Output is correct |
11 |
Correct |
35 ms |
222032 KB |
Output is correct |
12 |
Correct |
37 ms |
222044 KB |
Output is correct |
13 |
Correct |
36 ms |
221956 KB |
Output is correct |
14 |
Correct |
36 ms |
219976 KB |
Output is correct |
15 |
Correct |
34 ms |
219988 KB |
Output is correct |
16 |
Correct |
37 ms |
219984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
217936 KB |
Output is correct |
2 |
Correct |
35 ms |
217812 KB |
Output is correct |
3 |
Correct |
35 ms |
218104 KB |
Output is correct |
4 |
Correct |
35 ms |
217936 KB |
Output is correct |
5 |
Correct |
36 ms |
217936 KB |
Output is correct |
6 |
Correct |
39 ms |
222032 KB |
Output is correct |
7 |
Correct |
35 ms |
222020 KB |
Output is correct |
8 |
Correct |
35 ms |
222032 KB |
Output is correct |
9 |
Correct |
38 ms |
222032 KB |
Output is correct |
10 |
Correct |
37 ms |
220028 KB |
Output is correct |
11 |
Correct |
35 ms |
222032 KB |
Output is correct |
12 |
Correct |
37 ms |
222044 KB |
Output is correct |
13 |
Correct |
36 ms |
221956 KB |
Output is correct |
14 |
Correct |
36 ms |
219976 KB |
Output is correct |
15 |
Correct |
34 ms |
219988 KB |
Output is correct |
16 |
Correct |
37 ms |
219984 KB |
Output is correct |
17 |
Correct |
34 ms |
222024 KB |
Output is correct |
18 |
Correct |
44 ms |
222000 KB |
Output is correct |
19 |
Correct |
36 ms |
224240 KB |
Output is correct |
20 |
Correct |
36 ms |
224092 KB |
Output is correct |
21 |
Correct |
38 ms |
224080 KB |
Output is correct |
22 |
Correct |
38 ms |
224080 KB |
Output is correct |
23 |
Correct |
36 ms |
224252 KB |
Output is correct |
24 |
Correct |
37 ms |
219916 KB |
Output is correct |
25 |
Correct |
40 ms |
217936 KB |
Output is correct |
26 |
Correct |
37 ms |
217936 KB |
Output is correct |
27 |
Correct |
40 ms |
224080 KB |
Output is correct |
28 |
Correct |
37 ms |
224092 KB |
Output is correct |
29 |
Correct |
35 ms |
224072 KB |
Output is correct |
30 |
Correct |
40 ms |
221916 KB |
Output is correct |
31 |
Correct |
42 ms |
222032 KB |
Output is correct |
32 |
Correct |
40 ms |
222032 KB |
Output is correct |
33 |
Correct |
40 ms |
223912 KB |
Output is correct |
34 |
Correct |
39 ms |
224072 KB |
Output is correct |
35 |
Correct |
37 ms |
224072 KB |
Output is correct |
36 |
Correct |
36 ms |
224072 KB |
Output is correct |
37 |
Correct |
37 ms |
224092 KB |
Output is correct |
38 |
Correct |
38 ms |
223968 KB |
Output is correct |
39 |
Correct |
35 ms |
224080 KB |
Output is correct |
40 |
Correct |
35 ms |
224080 KB |
Output is correct |
41 |
Correct |
34 ms |
224084 KB |
Output is correct |
42 |
Correct |
34 ms |
224072 KB |
Output is correct |
43 |
Correct |
35 ms |
224080 KB |
Output is correct |
44 |
Correct |
35 ms |
224016 KB |
Output is correct |
45 |
Correct |
37 ms |
224080 KB |
Output is correct |
46 |
Correct |
35 ms |
224076 KB |
Output is correct |
47 |
Correct |
35 ms |
224072 KB |
Output is correct |
48 |
Correct |
37 ms |
224092 KB |
Output is correct |
49 |
Correct |
36 ms |
224040 KB |
Output is correct |
50 |
Correct |
35 ms |
224072 KB |
Output is correct |
51 |
Correct |
35 ms |
224080 KB |
Output is correct |
52 |
Correct |
35 ms |
224080 KB |
Output is correct |
53 |
Correct |
35 ms |
224080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
217936 KB |
Output is correct |
2 |
Correct |
35 ms |
217812 KB |
Output is correct |
3 |
Correct |
35 ms |
218104 KB |
Output is correct |
4 |
Correct |
35 ms |
217936 KB |
Output is correct |
5 |
Correct |
36 ms |
217936 KB |
Output is correct |
6 |
Correct |
39 ms |
222032 KB |
Output is correct |
7 |
Correct |
35 ms |
222020 KB |
Output is correct |
8 |
Correct |
35 ms |
222032 KB |
Output is correct |
9 |
Correct |
38 ms |
222032 KB |
Output is correct |
10 |
Correct |
37 ms |
220028 KB |
Output is correct |
11 |
Correct |
35 ms |
222032 KB |
Output is correct |
12 |
Correct |
37 ms |
222044 KB |
Output is correct |
13 |
Correct |
36 ms |
221956 KB |
Output is correct |
14 |
Correct |
36 ms |
219976 KB |
Output is correct |
15 |
Correct |
34 ms |
219988 KB |
Output is correct |
16 |
Correct |
37 ms |
219984 KB |
Output is correct |
17 |
Correct |
34 ms |
222024 KB |
Output is correct |
18 |
Correct |
44 ms |
222000 KB |
Output is correct |
19 |
Correct |
36 ms |
224240 KB |
Output is correct |
20 |
Correct |
36 ms |
224092 KB |
Output is correct |
21 |
Correct |
38 ms |
224080 KB |
Output is correct |
22 |
Correct |
38 ms |
224080 KB |
Output is correct |
23 |
Correct |
36 ms |
224252 KB |
Output is correct |
24 |
Correct |
37 ms |
219916 KB |
Output is correct |
25 |
Correct |
40 ms |
217936 KB |
Output is correct |
26 |
Correct |
37 ms |
217936 KB |
Output is correct |
27 |
Correct |
40 ms |
224080 KB |
Output is correct |
28 |
Correct |
37 ms |
224092 KB |
Output is correct |
29 |
Correct |
35 ms |
224072 KB |
Output is correct |
30 |
Correct |
40 ms |
221916 KB |
Output is correct |
31 |
Correct |
42 ms |
222032 KB |
Output is correct |
32 |
Correct |
40 ms |
222032 KB |
Output is correct |
33 |
Correct |
40 ms |
223912 KB |
Output is correct |
34 |
Correct |
39 ms |
224072 KB |
Output is correct |
35 |
Correct |
37 ms |
224072 KB |
Output is correct |
36 |
Correct |
36 ms |
224072 KB |
Output is correct |
37 |
Correct |
37 ms |
224092 KB |
Output is correct |
38 |
Correct |
38 ms |
223968 KB |
Output is correct |
39 |
Correct |
35 ms |
224080 KB |
Output is correct |
40 |
Correct |
35 ms |
224080 KB |
Output is correct |
41 |
Correct |
34 ms |
224084 KB |
Output is correct |
42 |
Correct |
34 ms |
224072 KB |
Output is correct |
43 |
Correct |
35 ms |
224080 KB |
Output is correct |
44 |
Correct |
35 ms |
224016 KB |
Output is correct |
45 |
Correct |
37 ms |
224080 KB |
Output is correct |
46 |
Correct |
35 ms |
224076 KB |
Output is correct |
47 |
Correct |
35 ms |
224072 KB |
Output is correct |
48 |
Correct |
37 ms |
224092 KB |
Output is correct |
49 |
Correct |
36 ms |
224040 KB |
Output is correct |
50 |
Correct |
35 ms |
224072 KB |
Output is correct |
51 |
Correct |
35 ms |
224080 KB |
Output is correct |
52 |
Correct |
35 ms |
224080 KB |
Output is correct |
53 |
Correct |
35 ms |
224080 KB |
Output is correct |
54 |
Correct |
39 ms |
219984 KB |
Output is correct |
55 |
Correct |
38 ms |
260160 KB |
Output is correct |
56 |
Correct |
36 ms |
222032 KB |
Output is correct |
57 |
Runtime error |
37 ms |
262144 KB |
Execution killed with signal 9 |
58 |
Halted |
0 ms |
0 KB |
- |