//#define _GLIBCXX_DEBUG
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
//randoms
//chrono::steady_clock::now().time_since_epoch().count()
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define trace(x) cout << #x << " = " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define ld long double
#define sz(s) (int) size(s)
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define int128 __int128
template<typename T>
void ckmn(T &x, T y) { if (x > y) { x = y; }}
template<typename T>
void ckmx(T &x, T y) { if (x < y) { x = y; }}
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const ll infL = 1e18;
const int infI = 1e9 + 7;
const int N = 3000000;
const ll mod = 998244353;
const ld eps = 1e-9;
int g[N][3];
int used[N], pr[N], T;
bool dfs(int v) {
if (used[v] == T) return false;
used[v] = T;
for (int to : g[v]) {
if (to != -1 && pr[to] == -1) {
pr[to] = v;
return true;
}
}
for (int to : g[v]) {
if (to != -1 && dfs(pr[to])) {
pr[to] = v;
return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> s(n);
vector<vector<int>> R(n, vector<int>(m, -1));
vector<vector<int>> D(n, vector<int>(m, -1));
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
memset(g, -1, sizeof(g));
int last = -1;
for (int i = 1; i < n - 1; ++i) {
for (int j = 0; j < m; ++j) {
if (s[i][j] == 'G' && s[i - 1][j] == 'R' && s[i + 1][j] == 'W') {
D[i][j] = D[i - 1][j] = D[i + 1][j] = ++last;
}
}
}
int gg = last;
last = -1;
for (int i = 0; i < n; ++i) {
for (int j = 1; j < m - 1; ++j) {
if (s[i][j] == 'G' && s[i][j - 1] == 'R' && s[i][j + 1] == 'W') {
R[i][j] = R[i][j - 1] = R[i][j + 1] = ++last;
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (D[i][j] != -1 && R[i][j] != -1) {
g[D[i][j]][used[D[i][j]]++] = R[i][j];
}
}
}
memset(used, 0, sizeof(used));
memset(pr, -1, sizeof(pr));
int ans = 0;
for (int i = 0; i <= gg; ++i) {
++T;
if (dfs(i))
++ans;
}
cout << gg + last - ans + 2;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
58988 KB |
Output is correct |
2 |
Correct |
21 ms |
58964 KB |
Output is correct |
3 |
Correct |
22 ms |
58952 KB |
Output is correct |
4 |
Correct |
22 ms |
59036 KB |
Output is correct |
5 |
Correct |
25 ms |
58964 KB |
Output is correct |
6 |
Correct |
21 ms |
58964 KB |
Output is correct |
7 |
Correct |
21 ms |
59004 KB |
Output is correct |
8 |
Correct |
21 ms |
58964 KB |
Output is correct |
9 |
Correct |
20 ms |
58964 KB |
Output is correct |
10 |
Correct |
22 ms |
58944 KB |
Output is correct |
11 |
Correct |
22 ms |
59012 KB |
Output is correct |
12 |
Correct |
22 ms |
59020 KB |
Output is correct |
13 |
Correct |
22 ms |
58956 KB |
Output is correct |
14 |
Correct |
27 ms |
58980 KB |
Output is correct |
15 |
Correct |
22 ms |
58964 KB |
Output is correct |
16 |
Correct |
23 ms |
58960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
58988 KB |
Output is correct |
2 |
Correct |
21 ms |
58964 KB |
Output is correct |
3 |
Correct |
22 ms |
58952 KB |
Output is correct |
4 |
Correct |
22 ms |
59036 KB |
Output is correct |
5 |
Correct |
25 ms |
58964 KB |
Output is correct |
6 |
Correct |
21 ms |
58964 KB |
Output is correct |
7 |
Correct |
21 ms |
59004 KB |
Output is correct |
8 |
Correct |
21 ms |
58964 KB |
Output is correct |
9 |
Correct |
20 ms |
58964 KB |
Output is correct |
10 |
Correct |
22 ms |
58944 KB |
Output is correct |
11 |
Correct |
22 ms |
59012 KB |
Output is correct |
12 |
Correct |
22 ms |
59020 KB |
Output is correct |
13 |
Correct |
22 ms |
58956 KB |
Output is correct |
14 |
Correct |
27 ms |
58980 KB |
Output is correct |
15 |
Correct |
22 ms |
58964 KB |
Output is correct |
16 |
Correct |
23 ms |
58960 KB |
Output is correct |
17 |
Correct |
21 ms |
58964 KB |
Output is correct |
18 |
Correct |
22 ms |
58960 KB |
Output is correct |
19 |
Correct |
21 ms |
58964 KB |
Output is correct |
20 |
Correct |
22 ms |
58904 KB |
Output is correct |
21 |
Correct |
22 ms |
59000 KB |
Output is correct |
22 |
Correct |
21 ms |
58964 KB |
Output is correct |
23 |
Correct |
23 ms |
58964 KB |
Output is correct |
24 |
Correct |
21 ms |
58924 KB |
Output is correct |
25 |
Correct |
21 ms |
58996 KB |
Output is correct |
26 |
Correct |
26 ms |
59028 KB |
Output is correct |
27 |
Correct |
22 ms |
58964 KB |
Output is correct |
28 |
Correct |
24 ms |
59072 KB |
Output is correct |
29 |
Correct |
23 ms |
58964 KB |
Output is correct |
30 |
Correct |
23 ms |
58988 KB |
Output is correct |
31 |
Correct |
22 ms |
58984 KB |
Output is correct |
32 |
Correct |
23 ms |
58968 KB |
Output is correct |
33 |
Correct |
23 ms |
58964 KB |
Output is correct |
34 |
Correct |
22 ms |
58932 KB |
Output is correct |
35 |
Correct |
22 ms |
58968 KB |
Output is correct |
36 |
Correct |
24 ms |
58964 KB |
Output is correct |
37 |
Correct |
22 ms |
58912 KB |
Output is correct |
38 |
Correct |
23 ms |
59012 KB |
Output is correct |
39 |
Correct |
24 ms |
58964 KB |
Output is correct |
40 |
Correct |
21 ms |
58916 KB |
Output is correct |
41 |
Correct |
23 ms |
58964 KB |
Output is correct |
42 |
Correct |
22 ms |
58928 KB |
Output is correct |
43 |
Correct |
23 ms |
58964 KB |
Output is correct |
44 |
Correct |
23 ms |
58964 KB |
Output is correct |
45 |
Correct |
22 ms |
58984 KB |
Output is correct |
46 |
Correct |
22 ms |
58976 KB |
Output is correct |
47 |
Correct |
22 ms |
58932 KB |
Output is correct |
48 |
Correct |
22 ms |
58964 KB |
Output is correct |
49 |
Correct |
26 ms |
58956 KB |
Output is correct |
50 |
Correct |
22 ms |
58940 KB |
Output is correct |
51 |
Correct |
21 ms |
58968 KB |
Output is correct |
52 |
Correct |
23 ms |
58964 KB |
Output is correct |
53 |
Correct |
22 ms |
58976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
58988 KB |
Output is correct |
2 |
Correct |
21 ms |
58964 KB |
Output is correct |
3 |
Correct |
22 ms |
58952 KB |
Output is correct |
4 |
Correct |
22 ms |
59036 KB |
Output is correct |
5 |
Correct |
25 ms |
58964 KB |
Output is correct |
6 |
Correct |
21 ms |
58964 KB |
Output is correct |
7 |
Correct |
21 ms |
59004 KB |
Output is correct |
8 |
Correct |
21 ms |
58964 KB |
Output is correct |
9 |
Correct |
20 ms |
58964 KB |
Output is correct |
10 |
Correct |
22 ms |
58944 KB |
Output is correct |
11 |
Correct |
22 ms |
59012 KB |
Output is correct |
12 |
Correct |
22 ms |
59020 KB |
Output is correct |
13 |
Correct |
22 ms |
58956 KB |
Output is correct |
14 |
Correct |
27 ms |
58980 KB |
Output is correct |
15 |
Correct |
22 ms |
58964 KB |
Output is correct |
16 |
Correct |
23 ms |
58960 KB |
Output is correct |
17 |
Correct |
21 ms |
58964 KB |
Output is correct |
18 |
Correct |
22 ms |
58960 KB |
Output is correct |
19 |
Correct |
21 ms |
58964 KB |
Output is correct |
20 |
Correct |
22 ms |
58904 KB |
Output is correct |
21 |
Correct |
22 ms |
59000 KB |
Output is correct |
22 |
Correct |
21 ms |
58964 KB |
Output is correct |
23 |
Correct |
23 ms |
58964 KB |
Output is correct |
24 |
Correct |
21 ms |
58924 KB |
Output is correct |
25 |
Correct |
21 ms |
58996 KB |
Output is correct |
26 |
Correct |
26 ms |
59028 KB |
Output is correct |
27 |
Correct |
22 ms |
58964 KB |
Output is correct |
28 |
Correct |
24 ms |
59072 KB |
Output is correct |
29 |
Correct |
23 ms |
58964 KB |
Output is correct |
30 |
Correct |
23 ms |
58988 KB |
Output is correct |
31 |
Correct |
22 ms |
58984 KB |
Output is correct |
32 |
Correct |
23 ms |
58968 KB |
Output is correct |
33 |
Correct |
23 ms |
58964 KB |
Output is correct |
34 |
Correct |
22 ms |
58932 KB |
Output is correct |
35 |
Correct |
22 ms |
58968 KB |
Output is correct |
36 |
Correct |
24 ms |
58964 KB |
Output is correct |
37 |
Correct |
22 ms |
58912 KB |
Output is correct |
38 |
Correct |
23 ms |
59012 KB |
Output is correct |
39 |
Correct |
24 ms |
58964 KB |
Output is correct |
40 |
Correct |
21 ms |
58916 KB |
Output is correct |
41 |
Correct |
23 ms |
58964 KB |
Output is correct |
42 |
Correct |
22 ms |
58928 KB |
Output is correct |
43 |
Correct |
23 ms |
58964 KB |
Output is correct |
44 |
Correct |
23 ms |
58964 KB |
Output is correct |
45 |
Correct |
22 ms |
58984 KB |
Output is correct |
46 |
Correct |
22 ms |
58976 KB |
Output is correct |
47 |
Correct |
22 ms |
58932 KB |
Output is correct |
48 |
Correct |
22 ms |
58964 KB |
Output is correct |
49 |
Correct |
26 ms |
58956 KB |
Output is correct |
50 |
Correct |
22 ms |
58940 KB |
Output is correct |
51 |
Correct |
21 ms |
58968 KB |
Output is correct |
52 |
Correct |
23 ms |
58964 KB |
Output is correct |
53 |
Correct |
22 ms |
58976 KB |
Output is correct |
54 |
Correct |
21 ms |
59012 KB |
Output is correct |
55 |
Correct |
23 ms |
59348 KB |
Output is correct |
56 |
Correct |
22 ms |
59092 KB |
Output is correct |
57 |
Correct |
24 ms |
59344 KB |
Output is correct |
58 |
Correct |
43 ms |
68976 KB |
Output is correct |
59 |
Correct |
188 ms |
148296 KB |
Output is correct |
60 |
Correct |
184 ms |
148492 KB |
Output is correct |
61 |
Correct |
188 ms |
148340 KB |
Output is correct |
62 |
Correct |
21 ms |
59092 KB |
Output is correct |
63 |
Correct |
180 ms |
145256 KB |
Output is correct |
64 |
Correct |
170 ms |
148444 KB |
Output is correct |
65 |
Correct |
212 ms |
148476 KB |
Output is correct |
66 |
Correct |
229 ms |
148460 KB |
Output is correct |
67 |
Correct |
129 ms |
148300 KB |
Output is correct |
68 |
Correct |
126 ms |
148340 KB |
Output is correct |
69 |
Correct |
137 ms |
148260 KB |
Output is correct |
70 |
Correct |
40 ms |
68940 KB |
Output is correct |
71 |
Correct |
41 ms |
69016 KB |
Output is correct |
72 |
Correct |
40 ms |
68928 KB |
Output is correct |
73 |
Correct |
43 ms |
68932 KB |
Output is correct |
74 |
Correct |
39 ms |
69040 KB |
Output is correct |
75 |
Correct |
40 ms |
68972 KB |
Output is correct |
76 |
Correct |
41 ms |
68952 KB |
Output is correct |
77 |
Correct |
40 ms |
68940 KB |
Output is correct |
78 |
Correct |
46 ms |
69044 KB |
Output is correct |
79 |
Correct |
40 ms |
68964 KB |
Output is correct |
80 |
Correct |
40 ms |
68992 KB |
Output is correct |
81 |
Correct |
40 ms |
68936 KB |
Output is correct |
82 |
Correct |
42 ms |
69032 KB |
Output is correct |
83 |
Correct |
43 ms |
69024 KB |
Output is correct |
84 |
Correct |
40 ms |
68924 KB |
Output is correct |
85 |
Correct |
42 ms |
69052 KB |
Output is correct |
86 |
Correct |
45 ms |
69036 KB |
Output is correct |
87 |
Correct |
43 ms |
68964 KB |
Output is correct |
88 |
Correct |
41 ms |
68956 KB |
Output is correct |
89 |
Correct |
40 ms |
69020 KB |
Output is correct |
90 |
Correct |
44 ms |
69036 KB |
Output is correct |