#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset
using namespace std;
typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;
const int maxn = 3020;
const int maxm = 3000020;
const int MOd = 1e9 + 7;
int a, b;
int cnt = 0;
char ar[maxn][maxn];
int ex[maxn][maxn][2];
int used[maxm], sz[maxm], in[maxm];
queue<int> q;
vector<int> w[maxm];
void con( int x, int y ) {
if( x && y ) {
w[x].pb( y );
w[y].pb( x );
sz[x]++;
sz[y]++;
}
}
void rem( int n ) {
if( used[n] ) return;
used[n] = 1;
for(int i=0;i<w[n].size();i++) {
int t = w[n][i];
sz[t]--;
if( sz[t] <= 1 && !used[t] && !in[t] ) q.push( t ), in[t] = 1;
}
}
int main() {
//freopen("asd.in","r",stdin);
//freopen("output17.txt","w",stdout);
scanf("%d %d",&a,&b);
for(int i=1;i<=a;i++)
scanf(" %s",ar[i]+1);
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++) {
if( ar[i][j] != 'R' ) continue;
if( j+2 <= b && ar[i][j+1] == 'G' && ar[i][j+2] == 'W' ) ex[i][j][0] = ++cnt;
if( i+2 <= a && ar[i+1][j] == 'G' && ar[i+2][j] == 'W' ) ex[i][j][1] = ++cnt;
}
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++) {
con( ex[i][j][0], ex[i][j][1] );
con( ex[i][j][0], ex[i-1][j+1][1] );
if( i >= 3 ) con( ex[i][j][0], ex[i-2][j+2][1] );
}
//cnt = 3000000;
int ans = 0;
for(int i=1;i<=cnt;i++)
if( sz[i] <= 1 && !in[i] ) q.push( i ), in[i] = 1;
//printf("cnt=%d\n",cnt);
int last = 1;
while( last <= cnt ) {
while( !q.empty() ) {
int t = q.front();
q.pop();
if( used[t] ) continue;
rem( t );
ans++;
for(int i=0;i<w[t].size();i++)
rem( w[t][i] );
}
while( last <= cnt && used[last] ) last++;
if( last <= cnt ) q.push( last );
}
cout << ans << endl;
return 0;
}
Compilation message
dango_maker.cpp: In function 'void rem(int)':
dango_maker.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w[n].size();i++) {
~^~~~~~~~~~~~
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:104:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<w[t].size();i++)
~^~~~~~~~~~~~
dango_maker.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a,&b);
~~~~~^~~~~~~~~~~~~~~
dango_maker.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s",ar[i]+1);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
70776 KB |
Output is correct |
2 |
Correct |
72 ms |
70892 KB |
Output is correct |
3 |
Correct |
61 ms |
70940 KB |
Output is correct |
4 |
Correct |
62 ms |
70940 KB |
Output is correct |
5 |
Correct |
65 ms |
71004 KB |
Output is correct |
6 |
Correct |
62 ms |
71004 KB |
Output is correct |
7 |
Correct |
65 ms |
71004 KB |
Output is correct |
8 |
Correct |
65 ms |
71016 KB |
Output is correct |
9 |
Correct |
64 ms |
71028 KB |
Output is correct |
10 |
Correct |
73 ms |
71032 KB |
Output is correct |
11 |
Correct |
73 ms |
71032 KB |
Output is correct |
12 |
Correct |
73 ms |
71088 KB |
Output is correct |
13 |
Correct |
71 ms |
71088 KB |
Output is correct |
14 |
Correct |
67 ms |
71088 KB |
Output is correct |
15 |
Correct |
65 ms |
71088 KB |
Output is correct |
16 |
Correct |
65 ms |
71088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
70776 KB |
Output is correct |
2 |
Correct |
72 ms |
70892 KB |
Output is correct |
3 |
Correct |
61 ms |
70940 KB |
Output is correct |
4 |
Correct |
62 ms |
70940 KB |
Output is correct |
5 |
Correct |
65 ms |
71004 KB |
Output is correct |
6 |
Correct |
62 ms |
71004 KB |
Output is correct |
7 |
Correct |
65 ms |
71004 KB |
Output is correct |
8 |
Correct |
65 ms |
71016 KB |
Output is correct |
9 |
Correct |
64 ms |
71028 KB |
Output is correct |
10 |
Correct |
73 ms |
71032 KB |
Output is correct |
11 |
Correct |
73 ms |
71032 KB |
Output is correct |
12 |
Correct |
73 ms |
71088 KB |
Output is correct |
13 |
Correct |
71 ms |
71088 KB |
Output is correct |
14 |
Correct |
67 ms |
71088 KB |
Output is correct |
15 |
Correct |
65 ms |
71088 KB |
Output is correct |
16 |
Correct |
65 ms |
71088 KB |
Output is correct |
17 |
Correct |
71 ms |
71092 KB |
Output is correct |
18 |
Correct |
72 ms |
71120 KB |
Output is correct |
19 |
Correct |
63 ms |
71136 KB |
Output is correct |
20 |
Correct |
68 ms |
71220 KB |
Output is correct |
21 |
Correct |
69 ms |
71220 KB |
Output is correct |
22 |
Correct |
61 ms |
71240 KB |
Output is correct |
23 |
Correct |
67 ms |
71240 KB |
Output is correct |
24 |
Correct |
60 ms |
71240 KB |
Output is correct |
25 |
Correct |
73 ms |
71240 KB |
Output is correct |
26 |
Correct |
70 ms |
71240 KB |
Output is correct |
27 |
Correct |
72 ms |
71240 KB |
Output is correct |
28 |
Correct |
69 ms |
71248 KB |
Output is correct |
29 |
Correct |
75 ms |
71252 KB |
Output is correct |
30 |
Correct |
78 ms |
71256 KB |
Output is correct |
31 |
Correct |
69 ms |
71256 KB |
Output is correct |
32 |
Correct |
77 ms |
71256 KB |
Output is correct |
33 |
Correct |
72 ms |
71260 KB |
Output is correct |
34 |
Correct |
68 ms |
71264 KB |
Output is correct |
35 |
Correct |
65 ms |
71264 KB |
Output is correct |
36 |
Correct |
77 ms |
71296 KB |
Output is correct |
37 |
Correct |
61 ms |
71300 KB |
Output is correct |
38 |
Correct |
76 ms |
71304 KB |
Output is correct |
39 |
Correct |
61 ms |
71304 KB |
Output is correct |
40 |
Correct |
62 ms |
71312 KB |
Output is correct |
41 |
Correct |
62 ms |
71316 KB |
Output is correct |
42 |
Correct |
62 ms |
71320 KB |
Output is correct |
43 |
Correct |
60 ms |
71324 KB |
Output is correct |
44 |
Correct |
61 ms |
71452 KB |
Output is correct |
45 |
Correct |
71 ms |
71492 KB |
Output is correct |
46 |
Correct |
67 ms |
71492 KB |
Output is correct |
47 |
Correct |
65 ms |
71492 KB |
Output is correct |
48 |
Correct |
72 ms |
71492 KB |
Output is correct |
49 |
Correct |
61 ms |
71492 KB |
Output is correct |
50 |
Correct |
63 ms |
71492 KB |
Output is correct |
51 |
Correct |
65 ms |
71492 KB |
Output is correct |
52 |
Correct |
66 ms |
71492 KB |
Output is correct |
53 |
Correct |
63 ms |
71492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
70776 KB |
Output is correct |
2 |
Correct |
72 ms |
70892 KB |
Output is correct |
3 |
Correct |
61 ms |
70940 KB |
Output is correct |
4 |
Correct |
62 ms |
70940 KB |
Output is correct |
5 |
Correct |
65 ms |
71004 KB |
Output is correct |
6 |
Correct |
62 ms |
71004 KB |
Output is correct |
7 |
Correct |
65 ms |
71004 KB |
Output is correct |
8 |
Correct |
65 ms |
71016 KB |
Output is correct |
9 |
Correct |
64 ms |
71028 KB |
Output is correct |
10 |
Correct |
73 ms |
71032 KB |
Output is correct |
11 |
Correct |
73 ms |
71032 KB |
Output is correct |
12 |
Correct |
73 ms |
71088 KB |
Output is correct |
13 |
Correct |
71 ms |
71088 KB |
Output is correct |
14 |
Correct |
67 ms |
71088 KB |
Output is correct |
15 |
Correct |
65 ms |
71088 KB |
Output is correct |
16 |
Correct |
65 ms |
71088 KB |
Output is correct |
17 |
Correct |
71 ms |
71092 KB |
Output is correct |
18 |
Correct |
72 ms |
71120 KB |
Output is correct |
19 |
Correct |
63 ms |
71136 KB |
Output is correct |
20 |
Correct |
68 ms |
71220 KB |
Output is correct |
21 |
Correct |
69 ms |
71220 KB |
Output is correct |
22 |
Correct |
61 ms |
71240 KB |
Output is correct |
23 |
Correct |
67 ms |
71240 KB |
Output is correct |
24 |
Correct |
60 ms |
71240 KB |
Output is correct |
25 |
Correct |
73 ms |
71240 KB |
Output is correct |
26 |
Correct |
70 ms |
71240 KB |
Output is correct |
27 |
Correct |
72 ms |
71240 KB |
Output is correct |
28 |
Correct |
69 ms |
71248 KB |
Output is correct |
29 |
Correct |
75 ms |
71252 KB |
Output is correct |
30 |
Correct |
78 ms |
71256 KB |
Output is correct |
31 |
Correct |
69 ms |
71256 KB |
Output is correct |
32 |
Correct |
77 ms |
71256 KB |
Output is correct |
33 |
Correct |
72 ms |
71260 KB |
Output is correct |
34 |
Correct |
68 ms |
71264 KB |
Output is correct |
35 |
Correct |
65 ms |
71264 KB |
Output is correct |
36 |
Correct |
77 ms |
71296 KB |
Output is correct |
37 |
Correct |
61 ms |
71300 KB |
Output is correct |
38 |
Correct |
76 ms |
71304 KB |
Output is correct |
39 |
Correct |
61 ms |
71304 KB |
Output is correct |
40 |
Correct |
62 ms |
71312 KB |
Output is correct |
41 |
Correct |
62 ms |
71316 KB |
Output is correct |
42 |
Correct |
62 ms |
71320 KB |
Output is correct |
43 |
Correct |
60 ms |
71324 KB |
Output is correct |
44 |
Correct |
61 ms |
71452 KB |
Output is correct |
45 |
Correct |
71 ms |
71492 KB |
Output is correct |
46 |
Correct |
67 ms |
71492 KB |
Output is correct |
47 |
Correct |
65 ms |
71492 KB |
Output is correct |
48 |
Correct |
72 ms |
71492 KB |
Output is correct |
49 |
Correct |
61 ms |
71492 KB |
Output is correct |
50 |
Correct |
63 ms |
71492 KB |
Output is correct |
51 |
Correct |
65 ms |
71492 KB |
Output is correct |
52 |
Correct |
66 ms |
71492 KB |
Output is correct |
53 |
Correct |
63 ms |
71492 KB |
Output is correct |
54 |
Correct |
70 ms |
71492 KB |
Output is correct |
55 |
Correct |
76 ms |
80820 KB |
Output is correct |
56 |
Correct |
66 ms |
80820 KB |
Output is correct |
57 |
Correct |
85 ms |
84488 KB |
Output is correct |
58 |
Correct |
110 ms |
89032 KB |
Output is correct |
59 |
Correct |
393 ms |
177904 KB |
Output is correct |
60 |
Correct |
382 ms |
186788 KB |
Output is correct |
61 |
Correct |
447 ms |
195588 KB |
Output is correct |
62 |
Correct |
66 ms |
195588 KB |
Output is correct |
63 |
Correct |
419 ms |
203528 KB |
Output is correct |
64 |
Execution timed out |
2057 ms |
263168 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |