This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
int n,m,cnt = 1;
char wd[3005][3005];
map<pair<int,int>, int> mp;
vector<int> v[1000005];
bool met[1000005];
int main()
{
scanf("%d %d",&n,&m);
for(int i = 0; i < n; i++)
{
scanf("%s",wd[i]);
for(int j = 0; j < m - 2; j++)
{
if(wd[i][j] == 'R' && wd[i][j + 1] == 'G' && wd[i][j + 2] == 'W')
mp[{i,j}] = cnt++;
}
}
for(int i = 0; i < n - 2; i++)
{
for(int j = 0; j < m; j++)
{
if(wd[i][j] == 'R' && wd[i + 1][j] == 'G' && wd[i + 2][j] == 'W')
{
if(mp[{i,j}])
{
v[mp[{i,j}]].pb(cnt);
v[cnt].pb(mp[{i,j}]);
}
if(mp[{i + 1,j}])
{
v[mp[{i + 1,j}]].pb(cnt);
v[cnt].pb(mp[{i + 1,j}]);
}
if(mp[{i + 2,j}])
{
v[mp[{i + 2,j}]].pb(cnt);
v[cnt].pb(mp[{i + 2,j}]);
}
cnt++;
}
}
}
int ans = 0;
for(int i = 1; i < cnt; i++)
{
if(!met[i])
{
int t[2] = {0,0};
queue<pair<int,int> > q;
met[i] = true;
q.push({i,0});
t[0]++;
while(!q.empty())
{
int nw = q.front().f;
int ty = q.front().s;
q.pop();
for(auto go: v[nw])
{
if(!met[go])
{
met[go] = true;
q.push({go,ty ^ 1});
t[ty ^ 1]++;
}
}
}
ans += max(t[0],t[1]);
}
}
printf("%d\n",ans);
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
dango_maker.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%s",wd[i]);
| ~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |