#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
using ll=long long;
const int N=3005, M=3e6+5;
const ll INF=1e18;
vector<int> E[M];
int vis[M], match[M];
int co[N][N], poz[N][N], pio[N][N];
int col=1;
bool dfs(int v){
vis[v]=col;
for(int u:E[v]){
if(!match[u]){
match[u]=v;
return 1;
}
else{
if(vis[match[u]]!=col && dfs(match[u])){
match[u]=v;
return 1;
}
}
}
return 0;
}
int main(){
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
string s;
cin>>s;
for(int j=0; j<m; j++){
if(s[j]=='R')co[i][j+1]=1;
else if(s[j]=='G')co[i][j+1]=2;
else co[i][j+1]=3;
}
}
int ans=0;
for(int s=2; s<=n+m; s++){
int wsk1=0, wsk2=0;
for(int i=1; i<=n; i++){
int j=s-i;
if(j>0 && j<=m){
if(co[i-1][j]==1 && co[i][j]==2 && co[i+1][j]==3){
pio[i][j]=++wsk1;
}
}
}
for(int i=1; i<=n; i++){
int j=s-i;
if(j>0 && j<=m){
if(co[i][j-1]==1 && co[i][j]==2 && co[i][j+1]==3){
poz[i][j]=++wsk2;
}
}
}
for(int i=1; i<=n; i++){
int j=s-i;
if(j>0 && j<=m){
if(pio[i][j] && poz[i-1][j+1])E[pio[i][j]].push_back(poz[i-1][j+1]);
if(pio[i][j] && poz[i+1][j-1])E[pio[i][j]].push_back(poz[i+1][j-1]);
if(pio[i][j] && poz[i][j])E[pio[i][j]].push_back(poz[i][j]);
}
}
ans+=wsk1+wsk2;
for(int i=1; i<=wsk1; i++){
if(dfs(i))ans--;
else{
col++;
if(dfs(i))ans--;
}
}
for(int i=0; i<=wsk1+wsk2; i++){
match[i]=vis[i]=0;
E[i].clear();
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70732 KB |
Output is correct |
2 |
Correct |
43 ms |
70656 KB |
Output is correct |
3 |
Correct |
38 ms |
70740 KB |
Output is correct |
4 |
Correct |
37 ms |
70704 KB |
Output is correct |
5 |
Correct |
38 ms |
70740 KB |
Output is correct |
6 |
Correct |
38 ms |
70772 KB |
Output is correct |
7 |
Correct |
37 ms |
70760 KB |
Output is correct |
8 |
Correct |
37 ms |
70740 KB |
Output is correct |
9 |
Correct |
36 ms |
70788 KB |
Output is correct |
10 |
Correct |
37 ms |
70732 KB |
Output is correct |
11 |
Correct |
37 ms |
70692 KB |
Output is correct |
12 |
Correct |
38 ms |
70708 KB |
Output is correct |
13 |
Correct |
37 ms |
70804 KB |
Output is correct |
14 |
Correct |
38 ms |
70760 KB |
Output is correct |
15 |
Correct |
38 ms |
70740 KB |
Output is correct |
16 |
Correct |
38 ms |
70784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70732 KB |
Output is correct |
2 |
Correct |
43 ms |
70656 KB |
Output is correct |
3 |
Correct |
38 ms |
70740 KB |
Output is correct |
4 |
Correct |
37 ms |
70704 KB |
Output is correct |
5 |
Correct |
38 ms |
70740 KB |
Output is correct |
6 |
Correct |
38 ms |
70772 KB |
Output is correct |
7 |
Correct |
37 ms |
70760 KB |
Output is correct |
8 |
Correct |
37 ms |
70740 KB |
Output is correct |
9 |
Correct |
36 ms |
70788 KB |
Output is correct |
10 |
Correct |
37 ms |
70732 KB |
Output is correct |
11 |
Correct |
37 ms |
70692 KB |
Output is correct |
12 |
Correct |
38 ms |
70708 KB |
Output is correct |
13 |
Correct |
37 ms |
70804 KB |
Output is correct |
14 |
Correct |
38 ms |
70760 KB |
Output is correct |
15 |
Correct |
38 ms |
70740 KB |
Output is correct |
16 |
Correct |
38 ms |
70784 KB |
Output is correct |
17 |
Correct |
37 ms |
70804 KB |
Output is correct |
18 |
Correct |
36 ms |
70756 KB |
Output is correct |
19 |
Correct |
38 ms |
70740 KB |
Output is correct |
20 |
Correct |
38 ms |
70840 KB |
Output is correct |
21 |
Correct |
43 ms |
70844 KB |
Output is correct |
22 |
Correct |
38 ms |
70784 KB |
Output is correct |
23 |
Correct |
39 ms |
70860 KB |
Output is correct |
24 |
Correct |
38 ms |
70740 KB |
Output is correct |
25 |
Correct |
38 ms |
70768 KB |
Output is correct |
26 |
Correct |
37 ms |
70752 KB |
Output is correct |
27 |
Correct |
44 ms |
70876 KB |
Output is correct |
28 |
Correct |
41 ms |
70760 KB |
Output is correct |
29 |
Correct |
38 ms |
70868 KB |
Output is correct |
30 |
Correct |
43 ms |
70740 KB |
Output is correct |
31 |
Correct |
37 ms |
70816 KB |
Output is correct |
32 |
Correct |
38 ms |
70816 KB |
Output is correct |
33 |
Correct |
38 ms |
70792 KB |
Output is correct |
34 |
Correct |
38 ms |
70820 KB |
Output is correct |
35 |
Correct |
38 ms |
70800 KB |
Output is correct |
36 |
Correct |
38 ms |
70864 KB |
Output is correct |
37 |
Correct |
38 ms |
70892 KB |
Output is correct |
38 |
Correct |
38 ms |
70868 KB |
Output is correct |
39 |
Correct |
37 ms |
70860 KB |
Output is correct |
40 |
Correct |
40 ms |
70860 KB |
Output is correct |
41 |
Correct |
38 ms |
70796 KB |
Output is correct |
42 |
Correct |
38 ms |
70868 KB |
Output is correct |
43 |
Correct |
39 ms |
70868 KB |
Output is correct |
44 |
Correct |
39 ms |
70744 KB |
Output is correct |
45 |
Correct |
38 ms |
70832 KB |
Output is correct |
46 |
Correct |
38 ms |
70860 KB |
Output is correct |
47 |
Correct |
43 ms |
70824 KB |
Output is correct |
48 |
Correct |
39 ms |
70776 KB |
Output is correct |
49 |
Correct |
39 ms |
70880 KB |
Output is correct |
50 |
Correct |
38 ms |
70852 KB |
Output is correct |
51 |
Correct |
37 ms |
70856 KB |
Output is correct |
52 |
Correct |
38 ms |
70872 KB |
Output is correct |
53 |
Correct |
41 ms |
70796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70732 KB |
Output is correct |
2 |
Correct |
43 ms |
70656 KB |
Output is correct |
3 |
Correct |
38 ms |
70740 KB |
Output is correct |
4 |
Correct |
37 ms |
70704 KB |
Output is correct |
5 |
Correct |
38 ms |
70740 KB |
Output is correct |
6 |
Correct |
38 ms |
70772 KB |
Output is correct |
7 |
Correct |
37 ms |
70760 KB |
Output is correct |
8 |
Correct |
37 ms |
70740 KB |
Output is correct |
9 |
Correct |
36 ms |
70788 KB |
Output is correct |
10 |
Correct |
37 ms |
70732 KB |
Output is correct |
11 |
Correct |
37 ms |
70692 KB |
Output is correct |
12 |
Correct |
38 ms |
70708 KB |
Output is correct |
13 |
Correct |
37 ms |
70804 KB |
Output is correct |
14 |
Correct |
38 ms |
70760 KB |
Output is correct |
15 |
Correct |
38 ms |
70740 KB |
Output is correct |
16 |
Correct |
38 ms |
70784 KB |
Output is correct |
17 |
Correct |
37 ms |
70804 KB |
Output is correct |
18 |
Correct |
36 ms |
70756 KB |
Output is correct |
19 |
Correct |
38 ms |
70740 KB |
Output is correct |
20 |
Correct |
38 ms |
70840 KB |
Output is correct |
21 |
Correct |
43 ms |
70844 KB |
Output is correct |
22 |
Correct |
38 ms |
70784 KB |
Output is correct |
23 |
Correct |
39 ms |
70860 KB |
Output is correct |
24 |
Correct |
38 ms |
70740 KB |
Output is correct |
25 |
Correct |
38 ms |
70768 KB |
Output is correct |
26 |
Correct |
37 ms |
70752 KB |
Output is correct |
27 |
Correct |
44 ms |
70876 KB |
Output is correct |
28 |
Correct |
41 ms |
70760 KB |
Output is correct |
29 |
Correct |
38 ms |
70868 KB |
Output is correct |
30 |
Correct |
43 ms |
70740 KB |
Output is correct |
31 |
Correct |
37 ms |
70816 KB |
Output is correct |
32 |
Correct |
38 ms |
70816 KB |
Output is correct |
33 |
Correct |
38 ms |
70792 KB |
Output is correct |
34 |
Correct |
38 ms |
70820 KB |
Output is correct |
35 |
Correct |
38 ms |
70800 KB |
Output is correct |
36 |
Correct |
38 ms |
70864 KB |
Output is correct |
37 |
Correct |
38 ms |
70892 KB |
Output is correct |
38 |
Correct |
38 ms |
70868 KB |
Output is correct |
39 |
Correct |
37 ms |
70860 KB |
Output is correct |
40 |
Correct |
40 ms |
70860 KB |
Output is correct |
41 |
Correct |
38 ms |
70796 KB |
Output is correct |
42 |
Correct |
38 ms |
70868 KB |
Output is correct |
43 |
Correct |
39 ms |
70868 KB |
Output is correct |
44 |
Correct |
39 ms |
70744 KB |
Output is correct |
45 |
Correct |
38 ms |
70832 KB |
Output is correct |
46 |
Correct |
38 ms |
70860 KB |
Output is correct |
47 |
Correct |
43 ms |
70824 KB |
Output is correct |
48 |
Correct |
39 ms |
70776 KB |
Output is correct |
49 |
Correct |
39 ms |
70880 KB |
Output is correct |
50 |
Correct |
38 ms |
70852 KB |
Output is correct |
51 |
Correct |
37 ms |
70856 KB |
Output is correct |
52 |
Correct |
38 ms |
70872 KB |
Output is correct |
53 |
Correct |
41 ms |
70796 KB |
Output is correct |
54 |
Correct |
38 ms |
70748 KB |
Output is correct |
55 |
Correct |
69 ms |
83308 KB |
Output is correct |
56 |
Correct |
39 ms |
70868 KB |
Output is correct |
57 |
Correct |
57 ms |
88780 KB |
Output is correct |
58 |
Correct |
109 ms |
94232 KB |
Output is correct |
59 |
Correct |
706 ms |
176564 KB |
Output is correct |
60 |
Correct |
686 ms |
176608 KB |
Output is correct |
61 |
Correct |
675 ms |
176700 KB |
Output is correct |
62 |
Correct |
38 ms |
70740 KB |
Output is correct |
63 |
Correct |
665 ms |
176520 KB |
Output is correct |
64 |
Correct |
739 ms |
185744 KB |
Output is correct |
65 |
Correct |
713 ms |
185716 KB |
Output is correct |
66 |
Correct |
709 ms |
185676 KB |
Output is correct |
67 |
Correct |
647 ms |
130624 KB |
Output is correct |
68 |
Correct |
667 ms |
130736 KB |
Output is correct |
69 |
Correct |
653 ms |
140724 KB |
Output is correct |
70 |
Correct |
107 ms |
95572 KB |
Output is correct |
71 |
Correct |
107 ms |
95520 KB |
Output is correct |
72 |
Correct |
104 ms |
95532 KB |
Output is correct |
73 |
Correct |
108 ms |
95580 KB |
Output is correct |
74 |
Correct |
107 ms |
95572 KB |
Output is correct |
75 |
Correct |
109 ms |
95596 KB |
Output is correct |
76 |
Correct |
110 ms |
95604 KB |
Output is correct |
77 |
Correct |
106 ms |
95588 KB |
Output is correct |
78 |
Correct |
106 ms |
95500 KB |
Output is correct |
79 |
Correct |
107 ms |
95464 KB |
Output is correct |
80 |
Correct |
105 ms |
95584 KB |
Output is correct |
81 |
Correct |
132 ms |
95584 KB |
Output is correct |
82 |
Correct |
111 ms |
95560 KB |
Output is correct |
83 |
Correct |
106 ms |
95564 KB |
Output is correct |
84 |
Correct |
106 ms |
95592 KB |
Output is correct |
85 |
Correct |
107 ms |
95564 KB |
Output is correct |
86 |
Correct |
106 ms |
95528 KB |
Output is correct |
87 |
Correct |
109 ms |
95532 KB |
Output is correct |
88 |
Correct |
117 ms |
95476 KB |
Output is correct |
89 |
Correct |
106 ms |
95572 KB |
Output is correct |
90 |
Correct |
106 ms |
95512 KB |
Output is correct |