#include<bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> rgw(n, vector<pair<int, int>>(m, pair<int, int>()));
vector<vector<char>> grid(n, vector<char>(m));
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
}
}
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == 'R' && i + 2 < n && grid[i + 1][j] == 'G' && grid[i + 2][j] == 'W') {
rgw[i + 1][j].first = 1;
}
if (grid[i][j] == 'R' && j + 2 < m && grid[i][j + 1] == 'G' && grid[i][j + 2] == 'W') {
rgw[i][j + 1].second = 1;
}
}
}
/*for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j++) {
cout << rgw[i][j].first << " " << rgw[i][j].second << endl;
}
}*/
long long prze, wyn = 0, akwyn;
for (int i = 1; i < n + m - 1; i++) {
akwyn = 0;
prze = 0;
for (int j = i; j >= 0; j--) {
if (i - j < n && j < m) {
if (rgw[i - j][j].first == 1 && rgw[i - j][j].second == 0) {
akwyn += 1 + prze;
prze = 0;
if (i - j + 1 < n && j - 1 < m) {
rgw[i - j + 1][j - 1].second = 0;
}
}
else if (rgw[i - j][j].first == 0 && rgw[i - j][j].second == 1) {
akwyn += 1 + prze;
prze = 0;
if (i - j + 1 < n && j - 1 < m) {
rgw[i - j + 1][j - 1].first = 0;
}
}
else if (rgw[i - j][j].first == 1 && rgw[i - j][j].second == 1) {
prze += 1;
}
else {
akwyn += prze;
prze = 0;
}
}
}
akwyn += prze;
wyn += akwyn;
}
cout << wyn;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
592 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
560 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
504 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
440 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
592 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
560 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
504 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
440 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
5 ms |
336 KB |
Output is correct |
55 |
Correct |
5 ms |
760 KB |
Output is correct |
56 |
Correct |
5 ms |
592 KB |
Output is correct |
57 |
Correct |
4 ms |
592 KB |
Output is correct |
58 |
Correct |
53 ms |
10184 KB |
Output is correct |
59 |
Correct |
466 ms |
86784 KB |
Output is correct |
60 |
Correct |
430 ms |
87880 KB |
Output is correct |
61 |
Correct |
457 ms |
87112 KB |
Output is correct |
62 |
Correct |
5 ms |
336 KB |
Output is correct |
63 |
Correct |
424 ms |
84040 KB |
Output is correct |
64 |
Correct |
396 ms |
86812 KB |
Output is correct |
65 |
Correct |
381 ms |
79704 KB |
Output is correct |
66 |
Correct |
372 ms |
79688 KB |
Output is correct |
67 |
Correct |
372 ms |
84560 KB |
Output is correct |
68 |
Correct |
377 ms |
88028 KB |
Output is correct |
69 |
Correct |
407 ms |
87624 KB |
Output is correct |
70 |
Correct |
41 ms |
9808 KB |
Output is correct |
71 |
Correct |
48 ms |
10080 KB |
Output is correct |
72 |
Correct |
39 ms |
10064 KB |
Output is correct |
73 |
Correct |
40 ms |
9380 KB |
Output is correct |
74 |
Correct |
40 ms |
9296 KB |
Output is correct |
75 |
Correct |
46 ms |
10064 KB |
Output is correct |
76 |
Correct |
41 ms |
10064 KB |
Output is correct |
77 |
Correct |
43 ms |
10168 KB |
Output is correct |
78 |
Correct |
39 ms |
10284 KB |
Output is correct |
79 |
Correct |
39 ms |
9296 KB |
Output is correct |
80 |
Correct |
41 ms |
10056 KB |
Output is correct |
81 |
Correct |
40 ms |
9296 KB |
Output is correct |
82 |
Correct |
41 ms |
10056 KB |
Output is correct |
83 |
Correct |
40 ms |
9296 KB |
Output is correct |
84 |
Correct |
40 ms |
9416 KB |
Output is correct |
85 |
Correct |
43 ms |
10064 KB |
Output is correct |
86 |
Correct |
41 ms |
10064 KB |
Output is correct |
87 |
Correct |
55 ms |
9476 KB |
Output is correct |
88 |
Correct |
40 ms |
10064 KB |
Output is correct |
89 |
Correct |
41 ms |
10064 KB |
Output is correct |
90 |
Correct |
41 ms |
9296 KB |
Output is correct |