#include <bits/stdc++.h>
using namespace std;
const long long MX=2020;
long long mtr[MX][MX];
char ch[MX][MX];
const long long MXK=MX*MX;
vector < long long > mas[2*MXK];
long long usea[2*MXK];
long long pr[2*MXK];
long long timer=0,koma,komb;
bool khuna(long long zar)
{
if(usea[zar])
{
return 0;
}
usea[zar]=1;
for(auto u:mas[zar])
{
if(pr[u]==0)
{
pr[zar]=u;
pr[u]=zar;
return 1;
}
}
for(auto u:mas[zar])
{
if(khuna(pr[u]))
{
pr[zar]=u;
pr[u]=zar;
return 1;
}
}
return 0;
}
void kntkhuna()
{
while(true)
{
fill(usea+1,usea+1+timer,0);
bool p=0;
for(long long i=1;i<=koma;i++)
{
if(pr[i]==0)
{
if(khuna(i))
{
p=1;
}
}
}
if(!p)
{
return;
}
}
return;
}
void DFS(long long zar)
{
usea[zar]=1;
if(zar<=koma)
{
for(auto u:mas[zar])
{
if(pr[u]!=zar && usea[u]==0)
{
DFS(u);
}
}
}
else
{
if(usea[pr[zar]]==0)
{
DFS(pr[zar]);
}
}
return;
}
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
long long n,m;
cin>>n>>m;
for(long long i=1;i<=n;i++)
{
for(long long j=1;j<=m;j++)
{
cin>>ch[i][j];
}
}
for(long long i=1;i<=n;i++)
{
for(long long j=1;(j+2)<=m;j++)
{
if(ch[i][j]=='R' && ch[i][j+1]=='G' && ch[i][j+2]=='W')
{
timer++;
mtr[i][j]=timer;
}
}
}
koma=timer;
for(long long i=1;(i+2)<=n;i++)
{
for(long long j=1;j<=m;j++)
{
if(ch[i][j]=='R' && ch[i+1][j]=='G' && ch[i+2][j]=='W')
{
timer++;
for(long long corx=i;corx<=(i+2);corx++)
{
for(long long cory=max(1LL,j-2);cory<=j;cory++)
{
if(mtr[corx][cory])
{
mas[mtr[corx][cory]].push_back(timer);
mas[timer].push_back(mtr[corx][cory]);
}
}
}
}
}
}
komb=timer-koma;
if(koma==0)
{
cout<<komb<<"\n";
return 0;
}
if(komb==0)
{
cout<<koma<<"\n";
return 0;
}
kntkhuna();
fill(usea+1,usea+koma+komb+1,0);
for(long long i=1;i<=koma;i++)
{
if(pr[i]==0)
{
DFS(i);
}
}
long long res=0;
for(long long i=1;i<=koma;i++)
{
res+=(usea[i]==1);
}
for(long long i=(koma+1);i<=(koma+komb);i++)
{
res+=(usea[i]==0);
}
cout<<res<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
193108 KB |
Output is correct |
2 |
Correct |
43 ms |
193236 KB |
Output is correct |
3 |
Correct |
42 ms |
193116 KB |
Output is correct |
4 |
Correct |
42 ms |
193280 KB |
Output is correct |
5 |
Correct |
43 ms |
193108 KB |
Output is correct |
6 |
Correct |
44 ms |
197200 KB |
Output is correct |
7 |
Correct |
42 ms |
197208 KB |
Output is correct |
8 |
Correct |
43 ms |
197212 KB |
Output is correct |
9 |
Correct |
46 ms |
197196 KB |
Output is correct |
10 |
Correct |
42 ms |
193332 KB |
Output is correct |
11 |
Correct |
43 ms |
197384 KB |
Output is correct |
12 |
Correct |
45 ms |
197440 KB |
Output is correct |
13 |
Correct |
43 ms |
197212 KB |
Output is correct |
14 |
Correct |
42 ms |
193332 KB |
Output is correct |
15 |
Correct |
42 ms |
193192 KB |
Output is correct |
16 |
Correct |
42 ms |
193108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
193108 KB |
Output is correct |
2 |
Correct |
43 ms |
193236 KB |
Output is correct |
3 |
Correct |
42 ms |
193116 KB |
Output is correct |
4 |
Correct |
42 ms |
193280 KB |
Output is correct |
5 |
Correct |
43 ms |
193108 KB |
Output is correct |
6 |
Correct |
44 ms |
197200 KB |
Output is correct |
7 |
Correct |
42 ms |
197208 KB |
Output is correct |
8 |
Correct |
43 ms |
197212 KB |
Output is correct |
9 |
Correct |
46 ms |
197196 KB |
Output is correct |
10 |
Correct |
42 ms |
193332 KB |
Output is correct |
11 |
Correct |
43 ms |
197384 KB |
Output is correct |
12 |
Correct |
45 ms |
197440 KB |
Output is correct |
13 |
Correct |
43 ms |
197212 KB |
Output is correct |
14 |
Correct |
42 ms |
193332 KB |
Output is correct |
15 |
Correct |
42 ms |
193192 KB |
Output is correct |
16 |
Correct |
42 ms |
193108 KB |
Output is correct |
17 |
Correct |
43 ms |
197432 KB |
Output is correct |
18 |
Correct |
42 ms |
197200 KB |
Output is correct |
19 |
Correct |
43 ms |
197208 KB |
Output is correct |
20 |
Correct |
43 ms |
197212 KB |
Output is correct |
21 |
Correct |
42 ms |
197204 KB |
Output is correct |
22 |
Correct |
43 ms |
197204 KB |
Output is correct |
23 |
Correct |
43 ms |
197200 KB |
Output is correct |
24 |
Correct |
43 ms |
195412 KB |
Output is correct |
25 |
Correct |
43 ms |
193156 KB |
Output is correct |
26 |
Correct |
42 ms |
193160 KB |
Output is correct |
27 |
Correct |
44 ms |
197212 KB |
Output is correct |
28 |
Correct |
42 ms |
197304 KB |
Output is correct |
29 |
Correct |
43 ms |
197204 KB |
Output is correct |
30 |
Correct |
44 ms |
193296 KB |
Output is correct |
31 |
Correct |
42 ms |
193108 KB |
Output is correct |
32 |
Correct |
42 ms |
193108 KB |
Output is correct |
33 |
Correct |
43 ms |
197436 KB |
Output is correct |
34 |
Correct |
42 ms |
197212 KB |
Output is correct |
35 |
Correct |
43 ms |
197332 KB |
Output is correct |
36 |
Correct |
42 ms |
197200 KB |
Output is correct |
37 |
Correct |
42 ms |
197432 KB |
Output is correct |
38 |
Correct |
42 ms |
197208 KB |
Output is correct |
39 |
Correct |
42 ms |
197212 KB |
Output is correct |
40 |
Correct |
42 ms |
197352 KB |
Output is correct |
41 |
Correct |
43 ms |
197204 KB |
Output is correct |
42 |
Correct |
42 ms |
197212 KB |
Output is correct |
43 |
Correct |
43 ms |
197204 KB |
Output is correct |
44 |
Correct |
43 ms |
197204 KB |
Output is correct |
45 |
Correct |
42 ms |
197204 KB |
Output is correct |
46 |
Correct |
43 ms |
197256 KB |
Output is correct |
47 |
Correct |
43 ms |
197348 KB |
Output is correct |
48 |
Correct |
45 ms |
197724 KB |
Output is correct |
49 |
Correct |
44 ms |
197212 KB |
Output is correct |
50 |
Correct |
43 ms |
197452 KB |
Output is correct |
51 |
Correct |
43 ms |
197680 KB |
Output is correct |
52 |
Correct |
43 ms |
197208 KB |
Output is correct |
53 |
Correct |
43 ms |
197548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
193108 KB |
Output is correct |
2 |
Correct |
43 ms |
193236 KB |
Output is correct |
3 |
Correct |
42 ms |
193116 KB |
Output is correct |
4 |
Correct |
42 ms |
193280 KB |
Output is correct |
5 |
Correct |
43 ms |
193108 KB |
Output is correct |
6 |
Correct |
44 ms |
197200 KB |
Output is correct |
7 |
Correct |
42 ms |
197208 KB |
Output is correct |
8 |
Correct |
43 ms |
197212 KB |
Output is correct |
9 |
Correct |
46 ms |
197196 KB |
Output is correct |
10 |
Correct |
42 ms |
193332 KB |
Output is correct |
11 |
Correct |
43 ms |
197384 KB |
Output is correct |
12 |
Correct |
45 ms |
197440 KB |
Output is correct |
13 |
Correct |
43 ms |
197212 KB |
Output is correct |
14 |
Correct |
42 ms |
193332 KB |
Output is correct |
15 |
Correct |
42 ms |
193192 KB |
Output is correct |
16 |
Correct |
42 ms |
193108 KB |
Output is correct |
17 |
Correct |
43 ms |
197432 KB |
Output is correct |
18 |
Correct |
42 ms |
197200 KB |
Output is correct |
19 |
Correct |
43 ms |
197208 KB |
Output is correct |
20 |
Correct |
43 ms |
197212 KB |
Output is correct |
21 |
Correct |
42 ms |
197204 KB |
Output is correct |
22 |
Correct |
43 ms |
197204 KB |
Output is correct |
23 |
Correct |
43 ms |
197200 KB |
Output is correct |
24 |
Correct |
43 ms |
195412 KB |
Output is correct |
25 |
Correct |
43 ms |
193156 KB |
Output is correct |
26 |
Correct |
42 ms |
193160 KB |
Output is correct |
27 |
Correct |
44 ms |
197212 KB |
Output is correct |
28 |
Correct |
42 ms |
197304 KB |
Output is correct |
29 |
Correct |
43 ms |
197204 KB |
Output is correct |
30 |
Correct |
44 ms |
193296 KB |
Output is correct |
31 |
Correct |
42 ms |
193108 KB |
Output is correct |
32 |
Correct |
42 ms |
193108 KB |
Output is correct |
33 |
Correct |
43 ms |
197436 KB |
Output is correct |
34 |
Correct |
42 ms |
197212 KB |
Output is correct |
35 |
Correct |
43 ms |
197332 KB |
Output is correct |
36 |
Correct |
42 ms |
197200 KB |
Output is correct |
37 |
Correct |
42 ms |
197432 KB |
Output is correct |
38 |
Correct |
42 ms |
197208 KB |
Output is correct |
39 |
Correct |
42 ms |
197212 KB |
Output is correct |
40 |
Correct |
42 ms |
197352 KB |
Output is correct |
41 |
Correct |
43 ms |
197204 KB |
Output is correct |
42 |
Correct |
42 ms |
197212 KB |
Output is correct |
43 |
Correct |
43 ms |
197204 KB |
Output is correct |
44 |
Correct |
43 ms |
197204 KB |
Output is correct |
45 |
Correct |
42 ms |
197204 KB |
Output is correct |
46 |
Correct |
43 ms |
197256 KB |
Output is correct |
47 |
Correct |
43 ms |
197348 KB |
Output is correct |
48 |
Correct |
45 ms |
197724 KB |
Output is correct |
49 |
Correct |
44 ms |
197212 KB |
Output is correct |
50 |
Correct |
43 ms |
197452 KB |
Output is correct |
51 |
Correct |
43 ms |
197680 KB |
Output is correct |
52 |
Correct |
43 ms |
197208 KB |
Output is correct |
53 |
Correct |
43 ms |
197548 KB |
Output is correct |
54 |
Correct |
43 ms |
195256 KB |
Output is correct |
55 |
Execution timed out |
2316 ms |
262144 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |