#pragma GCC optimize("no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()
template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
const int MAXN = 3100;
char table[MAXN][MAXN];
vector<int> g[MAXN * MAXN];
int n, m;
void read() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table[i][j];
}
}
}
bool check_right(int i, int j) {
return j >= 0 && j + 2 < m && i >= 0 && i < n && table[i][j] == 'R' && table[i][j + 1] == 'G' && table[i][j + 2] == 'W';
}
bool check_down(int i, int j) {
return j >= 0 && j < m && i >= 0 && i + 2 < n && table[i][j] == 'R' && table[i + 1][j] == 'G' && table[i + 2][j] == 'W';
}
int cnt;
void build() {
cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!check_down(i, j)) continue;
if (check_right(i, j)) {
g[i * m + j].push_back(i * m + j);
}
if(check_right(i + 1, j - 1)) {
g[i * m + j].push_back((i + 1) * m + j - 1);
//cout << "puhh" << endl;
}
if (check_right(i + 2, j - 2)) {
g[i * m + j].push_back((i + 2) * m + j - 2);
//cout << "puhh" << endl;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cnt += check_right(i, j);
cnt += check_down(i, j);
}
}
}
int used[MAXN * MAXN];
int mt[MAXN * MAXN];
bool dfs(int v, int c) {
if (used[v] == c) return false;
used[v] = c;
for (auto i : g[v]) {
if (mt[i] == -1) {
mt[i] = v;
return true;
}
}
for (auto i : g[v]) {
if (dfs(mt[i], c)) {
mt[i] = v;
return true;
}
}
return false;
}
int ans;
void calc() {
for (int i = 0; i < n * m; i++) {
mt[i] = used[i] = -1;
}
int c = 0;
for (int i = 0; i < n * m; i++) {
dfs(i, c++);
}
ans = cnt;
for (int i = 0; i < n * m; i++) {
if (mt[i] != -1) {
ans--;
}
}
}
void run() {
build();
calc();
}
void write() {
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read();
run();
write();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
226040 KB |
Output is correct |
2 |
Correct |
153 ms |
226040 KB |
Output is correct |
3 |
Correct |
154 ms |
226040 KB |
Output is correct |
4 |
Correct |
153 ms |
226040 KB |
Output is correct |
5 |
Correct |
152 ms |
226040 KB |
Output is correct |
6 |
Correct |
161 ms |
226040 KB |
Output is correct |
7 |
Correct |
150 ms |
226040 KB |
Output is correct |
8 |
Correct |
150 ms |
226168 KB |
Output is correct |
9 |
Correct |
154 ms |
226040 KB |
Output is correct |
10 |
Correct |
149 ms |
226040 KB |
Output is correct |
11 |
Correct |
157 ms |
226168 KB |
Output is correct |
12 |
Correct |
153 ms |
226040 KB |
Output is correct |
13 |
Correct |
154 ms |
226040 KB |
Output is correct |
14 |
Correct |
151 ms |
226040 KB |
Output is correct |
15 |
Correct |
152 ms |
226128 KB |
Output is correct |
16 |
Correct |
154 ms |
226040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
226040 KB |
Output is correct |
2 |
Correct |
153 ms |
226040 KB |
Output is correct |
3 |
Correct |
154 ms |
226040 KB |
Output is correct |
4 |
Correct |
153 ms |
226040 KB |
Output is correct |
5 |
Correct |
152 ms |
226040 KB |
Output is correct |
6 |
Correct |
161 ms |
226040 KB |
Output is correct |
7 |
Correct |
150 ms |
226040 KB |
Output is correct |
8 |
Correct |
150 ms |
226168 KB |
Output is correct |
9 |
Correct |
154 ms |
226040 KB |
Output is correct |
10 |
Correct |
149 ms |
226040 KB |
Output is correct |
11 |
Correct |
157 ms |
226168 KB |
Output is correct |
12 |
Correct |
153 ms |
226040 KB |
Output is correct |
13 |
Correct |
154 ms |
226040 KB |
Output is correct |
14 |
Correct |
151 ms |
226040 KB |
Output is correct |
15 |
Correct |
152 ms |
226128 KB |
Output is correct |
16 |
Correct |
154 ms |
226040 KB |
Output is correct |
17 |
Correct |
160 ms |
226040 KB |
Output is correct |
18 |
Correct |
152 ms |
226040 KB |
Output is correct |
19 |
Correct |
149 ms |
226088 KB |
Output is correct |
20 |
Correct |
154 ms |
226040 KB |
Output is correct |
21 |
Correct |
154 ms |
226040 KB |
Output is correct |
22 |
Correct |
153 ms |
225996 KB |
Output is correct |
23 |
Correct |
151 ms |
226040 KB |
Output is correct |
24 |
Correct |
152 ms |
226040 KB |
Output is correct |
25 |
Correct |
154 ms |
226040 KB |
Output is correct |
26 |
Correct |
156 ms |
226040 KB |
Output is correct |
27 |
Correct |
159 ms |
226028 KB |
Output is correct |
28 |
Correct |
153 ms |
226040 KB |
Output is correct |
29 |
Correct |
156 ms |
226040 KB |
Output is correct |
30 |
Correct |
152 ms |
226040 KB |
Output is correct |
31 |
Correct |
153 ms |
226040 KB |
Output is correct |
32 |
Correct |
150 ms |
226040 KB |
Output is correct |
33 |
Correct |
152 ms |
226040 KB |
Output is correct |
34 |
Correct |
163 ms |
226016 KB |
Output is correct |
35 |
Correct |
151 ms |
226040 KB |
Output is correct |
36 |
Correct |
157 ms |
226040 KB |
Output is correct |
37 |
Correct |
167 ms |
226108 KB |
Output is correct |
38 |
Correct |
152 ms |
226044 KB |
Output is correct |
39 |
Correct |
160 ms |
226040 KB |
Output is correct |
40 |
Correct |
151 ms |
226040 KB |
Output is correct |
41 |
Correct |
172 ms |
226040 KB |
Output is correct |
42 |
Correct |
151 ms |
226040 KB |
Output is correct |
43 |
Correct |
154 ms |
226040 KB |
Output is correct |
44 |
Correct |
154 ms |
226168 KB |
Output is correct |
45 |
Correct |
158 ms |
226040 KB |
Output is correct |
46 |
Correct |
153 ms |
226040 KB |
Output is correct |
47 |
Correct |
155 ms |
226044 KB |
Output is correct |
48 |
Correct |
151 ms |
226040 KB |
Output is correct |
49 |
Correct |
152 ms |
226040 KB |
Output is correct |
50 |
Correct |
150 ms |
226040 KB |
Output is correct |
51 |
Correct |
152 ms |
226040 KB |
Output is correct |
52 |
Correct |
150 ms |
226296 KB |
Output is correct |
53 |
Correct |
154 ms |
226040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
226040 KB |
Output is correct |
2 |
Correct |
153 ms |
226040 KB |
Output is correct |
3 |
Correct |
154 ms |
226040 KB |
Output is correct |
4 |
Correct |
153 ms |
226040 KB |
Output is correct |
5 |
Correct |
152 ms |
226040 KB |
Output is correct |
6 |
Correct |
161 ms |
226040 KB |
Output is correct |
7 |
Correct |
150 ms |
226040 KB |
Output is correct |
8 |
Correct |
150 ms |
226168 KB |
Output is correct |
9 |
Correct |
154 ms |
226040 KB |
Output is correct |
10 |
Correct |
149 ms |
226040 KB |
Output is correct |
11 |
Correct |
157 ms |
226168 KB |
Output is correct |
12 |
Correct |
153 ms |
226040 KB |
Output is correct |
13 |
Correct |
154 ms |
226040 KB |
Output is correct |
14 |
Correct |
151 ms |
226040 KB |
Output is correct |
15 |
Correct |
152 ms |
226128 KB |
Output is correct |
16 |
Correct |
154 ms |
226040 KB |
Output is correct |
17 |
Correct |
160 ms |
226040 KB |
Output is correct |
18 |
Correct |
152 ms |
226040 KB |
Output is correct |
19 |
Correct |
149 ms |
226088 KB |
Output is correct |
20 |
Correct |
154 ms |
226040 KB |
Output is correct |
21 |
Correct |
154 ms |
226040 KB |
Output is correct |
22 |
Correct |
153 ms |
225996 KB |
Output is correct |
23 |
Correct |
151 ms |
226040 KB |
Output is correct |
24 |
Correct |
152 ms |
226040 KB |
Output is correct |
25 |
Correct |
154 ms |
226040 KB |
Output is correct |
26 |
Correct |
156 ms |
226040 KB |
Output is correct |
27 |
Correct |
159 ms |
226028 KB |
Output is correct |
28 |
Correct |
153 ms |
226040 KB |
Output is correct |
29 |
Correct |
156 ms |
226040 KB |
Output is correct |
30 |
Correct |
152 ms |
226040 KB |
Output is correct |
31 |
Correct |
153 ms |
226040 KB |
Output is correct |
32 |
Correct |
150 ms |
226040 KB |
Output is correct |
33 |
Correct |
152 ms |
226040 KB |
Output is correct |
34 |
Correct |
163 ms |
226016 KB |
Output is correct |
35 |
Correct |
151 ms |
226040 KB |
Output is correct |
36 |
Correct |
157 ms |
226040 KB |
Output is correct |
37 |
Correct |
167 ms |
226108 KB |
Output is correct |
38 |
Correct |
152 ms |
226044 KB |
Output is correct |
39 |
Correct |
160 ms |
226040 KB |
Output is correct |
40 |
Correct |
151 ms |
226040 KB |
Output is correct |
41 |
Correct |
172 ms |
226040 KB |
Output is correct |
42 |
Correct |
151 ms |
226040 KB |
Output is correct |
43 |
Correct |
154 ms |
226040 KB |
Output is correct |
44 |
Correct |
154 ms |
226168 KB |
Output is correct |
45 |
Correct |
158 ms |
226040 KB |
Output is correct |
46 |
Correct |
153 ms |
226040 KB |
Output is correct |
47 |
Correct |
155 ms |
226044 KB |
Output is correct |
48 |
Correct |
151 ms |
226040 KB |
Output is correct |
49 |
Correct |
152 ms |
226040 KB |
Output is correct |
50 |
Correct |
150 ms |
226040 KB |
Output is correct |
51 |
Correct |
152 ms |
226040 KB |
Output is correct |
52 |
Correct |
150 ms |
226296 KB |
Output is correct |
53 |
Correct |
154 ms |
226040 KB |
Output is correct |
54 |
Correct |
152 ms |
226040 KB |
Output is correct |
55 |
Correct |
154 ms |
235260 KB |
Output is correct |
56 |
Correct |
157 ms |
226168 KB |
Output is correct |
57 |
Correct |
159 ms |
232256 KB |
Output is correct |
58 |
Correct |
205 ms |
237304 KB |
Output is correct |
59 |
Runtime error |
517 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
60 |
Halted |
0 ms |
0 KB |
- |