//cf meowcneil; t.me/macneilbot
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <random>
#include <cassert>
using namespace std;
// #define int long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define f(a) for(int i = 0; i<a; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<str> vestr;
typedef vector<int> vei;
typedef vector<vector<int>> veve;
void solve() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<vector<short>> ct(n, vector<short>(m));
vector<vector<bool>> ok1(n, vector<bool>(m));
vector<vector<bool>> ok2(n, vector<bool>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i && i < n - 1 && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') ct[i][j]++;
if (i && i < n - 1 && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') ok1[i][j] = 1;
if (j && j < m - 1 && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') ct[i][j]++;
if (j && j < m - 1 && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') ok2[i][j] = 1;
}
}
int ans = 0;
for (int s = 0; s < n + m; ++s) {
bool curr = 0;
for (int i = s; i >= 0; --i) {
int j = s - i;
if (i >= n || j >= m) continue;
if (a[i][j] != 'G') continue;
if (ct[i][j] == 1) {
if (ok1[i][j]) {
if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
a[i - 1][j] = 'Q';
a[i + 1][j] = 'Q';
ans++;
}
}
else {
if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
a[i][j - 1] = 'Q';
a[i][j + 1] = 'Q';
ans++;
}
}
}
else if (ct[i][j] == 2) {
if (a[i - 1][j] != 'R' || a[i + 1][j] != 'W') {
if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
a[i][j - 1] = 'Q';
a[i][j + 1] = 'Q';
ans++;
}
continue;
}
if (a[i][j - 1] != 'R' || a[i][j + 1] != 'W') {
if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
a[i - 1][j] = 'Q';
a[i + 1][j] = 'Q';
ans++;
}
continue;
}
ans++;
}
}
}
cout << ans << '\n';
}
signed main() {
int tc = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
// cin >> tc;
#else
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// cin >> tc;
#endif
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
Compilation message
dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:57:14: warning: unused variable 'curr' [-Wunused-variable]
57 | bool curr = 0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
452 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
460 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
352 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
352 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
356 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
356 KB |
Output is correct |
48 |
Correct |
0 ms |
356 KB |
Output is correct |
49 |
Correct |
0 ms |
356 KB |
Output is correct |
50 |
Correct |
0 ms |
604 KB |
Output is correct |
51 |
Correct |
0 ms |
356 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
452 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
460 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
352 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
352 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
356 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
356 KB |
Output is correct |
48 |
Correct |
0 ms |
356 KB |
Output is correct |
49 |
Correct |
0 ms |
356 KB |
Output is correct |
50 |
Correct |
0 ms |
604 KB |
Output is correct |
51 |
Correct |
0 ms |
356 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
3 ms |
344 KB |
Output is correct |
55 |
Correct |
4 ms |
1368 KB |
Output is correct |
56 |
Correct |
3 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
22 ms |
4812 KB |
Output is correct |
59 |
Correct |
239 ms |
39108 KB |
Output is correct |
60 |
Correct |
238 ms |
39260 KB |
Output is correct |
61 |
Correct |
236 ms |
39248 KB |
Output is correct |
62 |
Correct |
3 ms |
348 KB |
Output is correct |
63 |
Correct |
222 ms |
38000 KB |
Output is correct |
64 |
Correct |
117 ms |
39356 KB |
Output is correct |
65 |
Correct |
124 ms |
39248 KB |
Output is correct |
66 |
Correct |
118 ms |
39264 KB |
Output is correct |
67 |
Correct |
130 ms |
39260 KB |
Output is correct |
68 |
Correct |
127 ms |
39248 KB |
Output is correct |
69 |
Correct |
145 ms |
39248 KB |
Output is correct |
70 |
Correct |
9 ms |
4696 KB |
Output is correct |
71 |
Correct |
9 ms |
4700 KB |
Output is correct |
72 |
Correct |
9 ms |
4700 KB |
Output is correct |
73 |
Correct |
9 ms |
4696 KB |
Output is correct |
74 |
Correct |
9 ms |
4700 KB |
Output is correct |
75 |
Correct |
9 ms |
4696 KB |
Output is correct |
76 |
Correct |
9 ms |
4872 KB |
Output is correct |
77 |
Correct |
9 ms |
4880 KB |
Output is correct |
78 |
Correct |
9 ms |
4700 KB |
Output is correct |
79 |
Correct |
9 ms |
4700 KB |
Output is correct |
80 |
Correct |
10 ms |
4880 KB |
Output is correct |
81 |
Correct |
9 ms |
4700 KB |
Output is correct |
82 |
Correct |
12 ms |
4948 KB |
Output is correct |
83 |
Correct |
11 ms |
5028 KB |
Output is correct |
84 |
Correct |
9 ms |
4712 KB |
Output is correct |
85 |
Correct |
11 ms |
4876 KB |
Output is correct |
86 |
Correct |
9 ms |
4700 KB |
Output is correct |
87 |
Correct |
9 ms |
4696 KB |
Output is correct |
88 |
Correct |
9 ms |
4700 KB |
Output is correct |
89 |
Correct |
9 ms |
4700 KB |
Output is correct |
90 |
Correct |
9 ms |
4700 KB |
Output is correct |