#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=3e3+7;
const int INF=1e18;
char c[N][N];
int col[N][N];
int row[N][N];
const int M=3e6+7;
vector<int> v[M];
int my[M];
bool vis[N];
bool dfs(int x){
vis[x]=true;
for(int i:v[x]){
if(my[i]==-1||(!vis[my[i]]&&dfs(my[i]))){
my[i]=x;
return true;
}
}
return false;
}
signed main(){
quick
int n,m;
cin>>n>>m;
rep(i,1,n){
rep(j,1,m) cin>>c[i][j];
}
int Cc=0;
int Cr=0;
rep(i,1,n){
rep(j,1,m){
if(j+2<=m&&c[i][j]=='R'&&c[i][j+1]=='G'&&c[i][j+2]=='W'){
++Cc;
rep(jx,j,j+2){
col[i][jx]=Cc;
}
}
if(i+2<=n&&c[i][j]=='R'&&c[i+1][j]=='G'&&c[i+2][j]=='W'){
++Cr;
rep(ix,i,i+2){
row[ix][j]=Cr;
}
}
}
}
int e=0;
rep(i,1,n){
rep(j,1,m){
if(col[i][j]&&row[i][j]){
v[col[i][j]].eb(row[i][j]);
e++;
}
}
}
fill(my,my+Cr+1,-1);
int ans=0;
rep(i,1,Cc){
ans+=dfs(i);
fill(vis,vis+Cc+1,0LL);
}
cout<<Cr+Cc-ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
70736 KB |
Output is correct |
2 |
Correct |
36 ms |
70680 KB |
Output is correct |
3 |
Correct |
37 ms |
70784 KB |
Output is correct |
4 |
Correct |
34 ms |
70712 KB |
Output is correct |
5 |
Correct |
33 ms |
70740 KB |
Output is correct |
6 |
Correct |
35 ms |
70708 KB |
Output is correct |
7 |
Correct |
34 ms |
70732 KB |
Output is correct |
8 |
Correct |
39 ms |
70732 KB |
Output is correct |
9 |
Correct |
37 ms |
70740 KB |
Output is correct |
10 |
Correct |
39 ms |
70736 KB |
Output is correct |
11 |
Correct |
44 ms |
70824 KB |
Output is correct |
12 |
Correct |
36 ms |
70860 KB |
Output is correct |
13 |
Correct |
37 ms |
70752 KB |
Output is correct |
14 |
Correct |
36 ms |
70736 KB |
Output is correct |
15 |
Correct |
36 ms |
70712 KB |
Output is correct |
16 |
Correct |
35 ms |
70700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
70736 KB |
Output is correct |
2 |
Correct |
36 ms |
70680 KB |
Output is correct |
3 |
Correct |
37 ms |
70784 KB |
Output is correct |
4 |
Correct |
34 ms |
70712 KB |
Output is correct |
5 |
Correct |
33 ms |
70740 KB |
Output is correct |
6 |
Correct |
35 ms |
70708 KB |
Output is correct |
7 |
Correct |
34 ms |
70732 KB |
Output is correct |
8 |
Correct |
39 ms |
70732 KB |
Output is correct |
9 |
Correct |
37 ms |
70740 KB |
Output is correct |
10 |
Correct |
39 ms |
70736 KB |
Output is correct |
11 |
Correct |
44 ms |
70824 KB |
Output is correct |
12 |
Correct |
36 ms |
70860 KB |
Output is correct |
13 |
Correct |
37 ms |
70752 KB |
Output is correct |
14 |
Correct |
36 ms |
70736 KB |
Output is correct |
15 |
Correct |
36 ms |
70712 KB |
Output is correct |
16 |
Correct |
35 ms |
70700 KB |
Output is correct |
17 |
Correct |
38 ms |
70732 KB |
Output is correct |
18 |
Correct |
44 ms |
70724 KB |
Output is correct |
19 |
Correct |
37 ms |
70824 KB |
Output is correct |
20 |
Correct |
41 ms |
70748 KB |
Output is correct |
21 |
Correct |
36 ms |
70836 KB |
Output is correct |
22 |
Correct |
35 ms |
70880 KB |
Output is correct |
23 |
Correct |
36 ms |
70768 KB |
Output is correct |
24 |
Correct |
41 ms |
70728 KB |
Output is correct |
25 |
Correct |
38 ms |
70692 KB |
Output is correct |
26 |
Correct |
43 ms |
70712 KB |
Output is correct |
27 |
Correct |
45 ms |
70924 KB |
Output is correct |
28 |
Correct |
38 ms |
70876 KB |
Output is correct |
29 |
Correct |
39 ms |
70884 KB |
Output is correct |
30 |
Correct |
36 ms |
70792 KB |
Output is correct |
31 |
Correct |
37 ms |
70740 KB |
Output is correct |
32 |
Correct |
40 ms |
70732 KB |
Output is correct |
33 |
Correct |
44 ms |
70864 KB |
Output is correct |
34 |
Correct |
37 ms |
70868 KB |
Output is correct |
35 |
Correct |
38 ms |
70844 KB |
Output is correct |
36 |
Correct |
36 ms |
70988 KB |
Output is correct |
37 |
Correct |
37 ms |
70876 KB |
Output is correct |
38 |
Correct |
37 ms |
70860 KB |
Output is correct |
39 |
Correct |
38 ms |
70776 KB |
Output is correct |
40 |
Correct |
38 ms |
70880 KB |
Output is correct |
41 |
Correct |
46 ms |
70868 KB |
Output is correct |
42 |
Correct |
37 ms |
70872 KB |
Output is correct |
43 |
Correct |
36 ms |
70856 KB |
Output is correct |
44 |
Correct |
38 ms |
70792 KB |
Output is correct |
45 |
Correct |
36 ms |
70912 KB |
Output is correct |
46 |
Correct |
36 ms |
70856 KB |
Output is correct |
47 |
Correct |
38 ms |
70916 KB |
Output is correct |
48 |
Correct |
43 ms |
70840 KB |
Output is correct |
49 |
Correct |
41 ms |
70860 KB |
Output is correct |
50 |
Correct |
44 ms |
70884 KB |
Output is correct |
51 |
Correct |
43 ms |
70844 KB |
Output is correct |
52 |
Correct |
36 ms |
70864 KB |
Output is correct |
53 |
Correct |
45 ms |
70928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
70736 KB |
Output is correct |
2 |
Correct |
36 ms |
70680 KB |
Output is correct |
3 |
Correct |
37 ms |
70784 KB |
Output is correct |
4 |
Correct |
34 ms |
70712 KB |
Output is correct |
5 |
Correct |
33 ms |
70740 KB |
Output is correct |
6 |
Correct |
35 ms |
70708 KB |
Output is correct |
7 |
Correct |
34 ms |
70732 KB |
Output is correct |
8 |
Correct |
39 ms |
70732 KB |
Output is correct |
9 |
Correct |
37 ms |
70740 KB |
Output is correct |
10 |
Correct |
39 ms |
70736 KB |
Output is correct |
11 |
Correct |
44 ms |
70824 KB |
Output is correct |
12 |
Correct |
36 ms |
70860 KB |
Output is correct |
13 |
Correct |
37 ms |
70752 KB |
Output is correct |
14 |
Correct |
36 ms |
70736 KB |
Output is correct |
15 |
Correct |
36 ms |
70712 KB |
Output is correct |
16 |
Correct |
35 ms |
70700 KB |
Output is correct |
17 |
Correct |
38 ms |
70732 KB |
Output is correct |
18 |
Correct |
44 ms |
70724 KB |
Output is correct |
19 |
Correct |
37 ms |
70824 KB |
Output is correct |
20 |
Correct |
41 ms |
70748 KB |
Output is correct |
21 |
Correct |
36 ms |
70836 KB |
Output is correct |
22 |
Correct |
35 ms |
70880 KB |
Output is correct |
23 |
Correct |
36 ms |
70768 KB |
Output is correct |
24 |
Correct |
41 ms |
70728 KB |
Output is correct |
25 |
Correct |
38 ms |
70692 KB |
Output is correct |
26 |
Correct |
43 ms |
70712 KB |
Output is correct |
27 |
Correct |
45 ms |
70924 KB |
Output is correct |
28 |
Correct |
38 ms |
70876 KB |
Output is correct |
29 |
Correct |
39 ms |
70884 KB |
Output is correct |
30 |
Correct |
36 ms |
70792 KB |
Output is correct |
31 |
Correct |
37 ms |
70740 KB |
Output is correct |
32 |
Correct |
40 ms |
70732 KB |
Output is correct |
33 |
Correct |
44 ms |
70864 KB |
Output is correct |
34 |
Correct |
37 ms |
70868 KB |
Output is correct |
35 |
Correct |
38 ms |
70844 KB |
Output is correct |
36 |
Correct |
36 ms |
70988 KB |
Output is correct |
37 |
Correct |
37 ms |
70876 KB |
Output is correct |
38 |
Correct |
37 ms |
70860 KB |
Output is correct |
39 |
Correct |
38 ms |
70776 KB |
Output is correct |
40 |
Correct |
38 ms |
70880 KB |
Output is correct |
41 |
Correct |
46 ms |
70868 KB |
Output is correct |
42 |
Correct |
37 ms |
70872 KB |
Output is correct |
43 |
Correct |
36 ms |
70856 KB |
Output is correct |
44 |
Correct |
38 ms |
70792 KB |
Output is correct |
45 |
Correct |
36 ms |
70912 KB |
Output is correct |
46 |
Correct |
36 ms |
70856 KB |
Output is correct |
47 |
Correct |
38 ms |
70916 KB |
Output is correct |
48 |
Correct |
43 ms |
70840 KB |
Output is correct |
49 |
Correct |
41 ms |
70860 KB |
Output is correct |
50 |
Correct |
44 ms |
70884 KB |
Output is correct |
51 |
Correct |
43 ms |
70844 KB |
Output is correct |
52 |
Correct |
36 ms |
70864 KB |
Output is correct |
53 |
Correct |
45 ms |
70928 KB |
Output is correct |
54 |
Correct |
43 ms |
70732 KB |
Output is correct |
55 |
Correct |
42 ms |
81104 KB |
Output is correct |
56 |
Correct |
37 ms |
71084 KB |
Output is correct |
57 |
Correct |
46 ms |
89580 KB |
Output is correct |
58 |
Incorrect |
119 ms |
98568 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |