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;
vector<vector<char>> a;
vector<vector<int>> used;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
a.resize(n);
used.resize(n);
for(int i = 0;i < n;++i)
{
a[i].resize(m);
used[i].resize(m);
string s;
cin >> s;
for(int j = 0;j < m;++j)
{
a[i][j] = s[j];
}
}
int ans = 0;
for(int i = 0;i < n;++i)
{
for(int j = 0;j < m;++j)
{
if(a[i][j] != 'R' || used[i][j])
continue;
if(j < m-2 && a[i][j+1] == 'G' && a[i][j+2] == 'W' && used[i][j+1]+used[i][j+2] == 0)
{
used[i][j] = 1;
used[i][j+1] = 1;
used[i][j+2] = 1;
ans++;
}
else if(i < n-2 && a[i+1][j] == 'G' && a[i+2][j] == 'W' && used[i+1][j]+used[i+2][j] == 0)
{
if(j > 0 && j < m-1 && a[i+1][j-1] == 'R' && a[i+1][j+1] == 'W' && used[i+1][j-1]+used[i+1][j+1] == 0)
{
used[i][j] = 1;
used[i+1][j] = 1;
used[i+1][j+1] = 1;
}
else
{
used[i][j] = 1;
used[i+1][j] = 1;
used[i+2][j] = 1;
}
ans++;
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |