#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<vi> vvi;
typedef pair<double, double> dodo;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
int N, M;
vvi edges;
int num_nodes = 0;
int createNode() {
edges.pb(vi());
return num_nodes++;
}
void connect(int a, int b) {
edges[a].pb(b);
edges[b].pb(a);
}
const int ARRSIZE = 3000*3000;
int parent[ARRSIZE];
bool vis[ARRSIZE] = {0};
int bfs(int x, bool b) {
int ret = 0;
queue<ii> Q;
Q.push(mp(x, (int)b));
while (!Q.empty()) {
ii a = Q.front(); Q.pop();
if (vis[a.first]) {
continue;
}
vis[a.first] = true;
ret += a.second;
for (int i = 0; i < edges[a.first].size(); i++) {
int y = edges[a.first][i];
Q.push(mp(y, !a.second));
}
}
return ret;
}
void clean(int x) {
vis[x] = false;
for (int i = 0; i < edges[x].size(); i++) {
int y = edges[x][i];
if (!vis[y]) continue;
clean(y);
}
}
int mat[3000][3000];
vi touch[3000][3000];
void func() {
cin >> N >> M;
for (int i = 0; i < N; i++) {
string s; cin >> s;
for (int j = 0; j < M; j++) {
if (s[j] == 'R') mat[i][j] = 0;
if (s[j] == 'G') mat[i][j] = 1;
if (s[j] == 'W') mat[i][j] = 2;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M-2; j++) {
if (mat[i][j]*9 + mat[i][j+1]*3 + mat[i][j+2]*1 == 5) {
int x = createNode();
/*if (touch[i][j].size() > 0) {
for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
}*/
touch[i][j].pb(x);
/*if (touch[i][j+1].size() > 0) {
for (int k = 0; k < touch[i][j+1].size(); k++) connect(x, touch[i][j+1][k]);
}*/
touch[i][j+1].pb(x);
/*if (touch[i][j+2].size() > 0) {
for (int k = 0; k < touch[i][j+2].size(); k++) connect(x, touch[i][j+2][k]);
}*/
touch[i][j+2].pb(x);
}
}
}
for (int i = 0; i < N-2; i++) {
for (int j = 0; j < M; j++) {
if (mat[i][j]*9 + mat[i+1][j]*3 + mat[i+2][j]*1 == 5) {
int x = createNode();
//if (touch[i][j].size() > 0) {
for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
//}
//touch[i][j].pb(x);
//if (touch[i+1][j].size() > 0) {
for (int k = 0; k < touch[i+1][j].size(); k++) connect(x, touch[i+1][j][k]);
//}
//touch[i+1][j].pb(x);
//if (touch[i+2][j].size() > 0) {
for (int k = 0; k < touch[i+2][j].size(); k++) connect(x, touch[i+2][j][k]);
//}
//touch[i+2][j].pb(x);
}
}
}
}
int count_component(int x) {
vis[x] = true;
int ret = 1;
for (int i = 0; i < edges[x].size(); i++) {
int y = edges[x][i];
if (vis[y]) continue;
ret += count_component(y);
}
return ret;
}
int es[ARRSIZE] = {0};
int main(int argc, char **argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
func();
if (N > 2000 && M > 2000) exit(-1);
int sum = 0;
set<ii> S;
for (int i = 0; i < num_nodes; i++) es[i] = edges[i].size();
for (int i = 0; i < num_nodes; i++) S.insert(mp(es[i], i));
while (!S.empty()) {
int x = (*S.begin()).second;
S.erase(S.begin());
for (int i = 0; i < edges[x].size(); i++) {
int y = edges[x][i];
auto it = S.find(mp(es[y], y));
if (it != S.end()) {
S.erase(it);
for (int j = 0; j < edges[y].size(); j++) {
int y2 = edges[y][j];
auto it2 = S.find(mp(es[y2], y2));
if (it2 != S.end()) {
S.erase(it2);
es[y2]--;
S.insert(mp(es[y2], y2));
}
}
}
}
sum++;
}
/*for (int i = 0; i < num_nodes; i++) {
if (vis[i]) continue;
int a = bfs(i, true);
clean(i);
int b = bfs(i, false);
assert(abs(a-b) <= 1);
sum += max(a, b);
}*/
cout << sum << endl;
return 0;
}
Compilation message
dango_maker.cpp: In function 'int bfs(int, bool)':
dango_maker.cpp:41:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < edges[a.first].size(); i++) {
~~^~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'void clean(int)':
dango_maker.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < edges[x].size(); i++) {
~~^~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'void func()':
dango_maker.cpp:94:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
~~^~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:98:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < touch[i+1][j].size(); k++) connect(x, touch[i+1][j][k]);
~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:102:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < touch[i+2][j].size(); k++) connect(x, touch[i+2][j][k]);
~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'int count_component(int)':
dango_maker.cpp:113:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < edges[x].size(); i++) {
~~^~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'int main(int, char**)':
dango_maker.cpp:137:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < edges[x].size(); i++) {
~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:142:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < edges[y].size(); j++) {
~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
211748 KB |
Output is correct |
2 |
Correct |
192 ms |
211940 KB |
Output is correct |
3 |
Correct |
200 ms |
211940 KB |
Output is correct |
4 |
Correct |
190 ms |
212036 KB |
Output is correct |
5 |
Correct |
193 ms |
212036 KB |
Output is correct |
6 |
Correct |
183 ms |
212036 KB |
Output is correct |
7 |
Correct |
213 ms |
212036 KB |
Output is correct |
8 |
Correct |
195 ms |
212036 KB |
Output is correct |
9 |
Correct |
201 ms |
212036 KB |
Output is correct |
10 |
Correct |
232 ms |
212036 KB |
Output is correct |
11 |
Correct |
181 ms |
212036 KB |
Output is correct |
12 |
Correct |
204 ms |
212036 KB |
Output is correct |
13 |
Correct |
181 ms |
212036 KB |
Output is correct |
14 |
Correct |
201 ms |
212036 KB |
Output is correct |
15 |
Correct |
181 ms |
212036 KB |
Output is correct |
16 |
Correct |
189 ms |
212036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
211748 KB |
Output is correct |
2 |
Correct |
192 ms |
211940 KB |
Output is correct |
3 |
Correct |
200 ms |
211940 KB |
Output is correct |
4 |
Correct |
190 ms |
212036 KB |
Output is correct |
5 |
Correct |
193 ms |
212036 KB |
Output is correct |
6 |
Correct |
183 ms |
212036 KB |
Output is correct |
7 |
Correct |
213 ms |
212036 KB |
Output is correct |
8 |
Correct |
195 ms |
212036 KB |
Output is correct |
9 |
Correct |
201 ms |
212036 KB |
Output is correct |
10 |
Correct |
232 ms |
212036 KB |
Output is correct |
11 |
Correct |
181 ms |
212036 KB |
Output is correct |
12 |
Correct |
204 ms |
212036 KB |
Output is correct |
13 |
Correct |
181 ms |
212036 KB |
Output is correct |
14 |
Correct |
201 ms |
212036 KB |
Output is correct |
15 |
Correct |
181 ms |
212036 KB |
Output is correct |
16 |
Correct |
189 ms |
212036 KB |
Output is correct |
17 |
Correct |
211 ms |
212044 KB |
Output is correct |
18 |
Correct |
189 ms |
212044 KB |
Output is correct |
19 |
Correct |
187 ms |
212044 KB |
Output is correct |
20 |
Correct |
181 ms |
212044 KB |
Output is correct |
21 |
Correct |
189 ms |
212140 KB |
Output is correct |
22 |
Correct |
190 ms |
212140 KB |
Output is correct |
23 |
Correct |
202 ms |
212140 KB |
Output is correct |
24 |
Correct |
196 ms |
212140 KB |
Output is correct |
25 |
Correct |
196 ms |
212140 KB |
Output is correct |
26 |
Correct |
193 ms |
212140 KB |
Output is correct |
27 |
Correct |
202 ms |
212140 KB |
Output is correct |
28 |
Correct |
217 ms |
212140 KB |
Output is correct |
29 |
Correct |
196 ms |
212180 KB |
Output is correct |
30 |
Correct |
205 ms |
212180 KB |
Output is correct |
31 |
Correct |
189 ms |
212180 KB |
Output is correct |
32 |
Correct |
195 ms |
212180 KB |
Output is correct |
33 |
Correct |
186 ms |
212180 KB |
Output is correct |
34 |
Correct |
180 ms |
212180 KB |
Output is correct |
35 |
Correct |
203 ms |
212180 KB |
Output is correct |
36 |
Correct |
216 ms |
212180 KB |
Output is correct |
37 |
Correct |
201 ms |
212180 KB |
Output is correct |
38 |
Correct |
198 ms |
212180 KB |
Output is correct |
39 |
Correct |
192 ms |
212180 KB |
Output is correct |
40 |
Correct |
223 ms |
212180 KB |
Output is correct |
41 |
Correct |
198 ms |
212180 KB |
Output is correct |
42 |
Correct |
193 ms |
212180 KB |
Output is correct |
43 |
Correct |
183 ms |
212180 KB |
Output is correct |
44 |
Correct |
188 ms |
212180 KB |
Output is correct |
45 |
Correct |
185 ms |
212180 KB |
Output is correct |
46 |
Correct |
187 ms |
212180 KB |
Output is correct |
47 |
Correct |
195 ms |
212180 KB |
Output is correct |
48 |
Correct |
199 ms |
212180 KB |
Output is correct |
49 |
Correct |
184 ms |
212180 KB |
Output is correct |
50 |
Correct |
181 ms |
212180 KB |
Output is correct |
51 |
Correct |
198 ms |
212180 KB |
Output is correct |
52 |
Correct |
191 ms |
212180 KB |
Output is correct |
53 |
Correct |
191 ms |
212180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
211748 KB |
Output is correct |
2 |
Correct |
192 ms |
211940 KB |
Output is correct |
3 |
Correct |
200 ms |
211940 KB |
Output is correct |
4 |
Correct |
190 ms |
212036 KB |
Output is correct |
5 |
Correct |
193 ms |
212036 KB |
Output is correct |
6 |
Correct |
183 ms |
212036 KB |
Output is correct |
7 |
Correct |
213 ms |
212036 KB |
Output is correct |
8 |
Correct |
195 ms |
212036 KB |
Output is correct |
9 |
Correct |
201 ms |
212036 KB |
Output is correct |
10 |
Correct |
232 ms |
212036 KB |
Output is correct |
11 |
Correct |
181 ms |
212036 KB |
Output is correct |
12 |
Correct |
204 ms |
212036 KB |
Output is correct |
13 |
Correct |
181 ms |
212036 KB |
Output is correct |
14 |
Correct |
201 ms |
212036 KB |
Output is correct |
15 |
Correct |
181 ms |
212036 KB |
Output is correct |
16 |
Correct |
189 ms |
212036 KB |
Output is correct |
17 |
Correct |
211 ms |
212044 KB |
Output is correct |
18 |
Correct |
189 ms |
212044 KB |
Output is correct |
19 |
Correct |
187 ms |
212044 KB |
Output is correct |
20 |
Correct |
181 ms |
212044 KB |
Output is correct |
21 |
Correct |
189 ms |
212140 KB |
Output is correct |
22 |
Correct |
190 ms |
212140 KB |
Output is correct |
23 |
Correct |
202 ms |
212140 KB |
Output is correct |
24 |
Correct |
196 ms |
212140 KB |
Output is correct |
25 |
Correct |
196 ms |
212140 KB |
Output is correct |
26 |
Correct |
193 ms |
212140 KB |
Output is correct |
27 |
Correct |
202 ms |
212140 KB |
Output is correct |
28 |
Correct |
217 ms |
212140 KB |
Output is correct |
29 |
Correct |
196 ms |
212180 KB |
Output is correct |
30 |
Correct |
205 ms |
212180 KB |
Output is correct |
31 |
Correct |
189 ms |
212180 KB |
Output is correct |
32 |
Correct |
195 ms |
212180 KB |
Output is correct |
33 |
Correct |
186 ms |
212180 KB |
Output is correct |
34 |
Correct |
180 ms |
212180 KB |
Output is correct |
35 |
Correct |
203 ms |
212180 KB |
Output is correct |
36 |
Correct |
216 ms |
212180 KB |
Output is correct |
37 |
Correct |
201 ms |
212180 KB |
Output is correct |
38 |
Correct |
198 ms |
212180 KB |
Output is correct |
39 |
Correct |
192 ms |
212180 KB |
Output is correct |
40 |
Correct |
223 ms |
212180 KB |
Output is correct |
41 |
Correct |
198 ms |
212180 KB |
Output is correct |
42 |
Correct |
193 ms |
212180 KB |
Output is correct |
43 |
Correct |
183 ms |
212180 KB |
Output is correct |
44 |
Correct |
188 ms |
212180 KB |
Output is correct |
45 |
Correct |
185 ms |
212180 KB |
Output is correct |
46 |
Correct |
187 ms |
212180 KB |
Output is correct |
47 |
Correct |
195 ms |
212180 KB |
Output is correct |
48 |
Correct |
199 ms |
212180 KB |
Output is correct |
49 |
Correct |
184 ms |
212180 KB |
Output is correct |
50 |
Correct |
181 ms |
212180 KB |
Output is correct |
51 |
Correct |
198 ms |
212180 KB |
Output is correct |
52 |
Correct |
191 ms |
212180 KB |
Output is correct |
53 |
Correct |
191 ms |
212180 KB |
Output is correct |
54 |
Correct |
185 ms |
212180 KB |
Output is correct |
55 |
Correct |
215 ms |
224100 KB |
Output is correct |
56 |
Correct |
193 ms |
224100 KB |
Output is correct |
57 |
Correct |
211 ms |
224100 KB |
Output is correct |
58 |
Correct |
292 ms |
230676 KB |
Output is correct |
59 |
Runtime error |
1646 ms |
263168 KB |
Execution failed because the return code was nonzero |
60 |
Halted |
0 ms |
0 KB |
- |