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>
#define mod 1000000007
#define int long long
// https://www.youtube.com/watch?v=t5GDacP_2pQ
using namespace std;
ifstream in ("film.in");
ofstream out ("film.out");
int pow (int a, int b)
{
int rez = 1;
while (b)
{
if (b&1)
rez = (rez * a) % mod;
a = (a * a) % mod;
b>>=1;
}
return rez;
}
int n, m;
int v[3010][3010];
int viz[3010][3010];
bool ok_lin (pair<int, int> poz1, pair<int, int> poz2, pair<int, int> poz3)
{
int cate = 0;
if (viz[poz1.first][poz1.second] == 1 || viz[poz2.first][poz2.second] == 1 || viz[poz3.first][poz3.second] == 1)
return false;
if (v[poz1.first][poz1.second] != 'R' || v[poz2.first][poz2.second] != 'G' || v[poz3.first][poz3.second] != 'W')
return 0;
if (!(poz1.first + 2 > n))
{
if (v[poz1.first + 1][poz1.second] == 'G' && v[poz1.first + 2][poz1.second] == 'W' && viz[poz1.first + 1][poz1.second] == 0 && viz[poz1.first + 2][poz1.second] == 0)
cate++;
}
if (!(poz2.first - 1 < 0 || poz2.first + 1 > n))
{
if (v[poz2.first - 1][poz2.second] == 'R' && v[poz2.first + 1][poz2.second] == 'W' && viz[poz2.first - 1][poz2.second] == 0 && viz[poz2.first + 1][poz2.second] == 0)
cate++;
}
if (!(poz2.first - 2 < 0))
{
if (v[poz3.first - 2][poz3.second] == 'R' && v[poz3.first - 1][poz3.second] == 'G' && viz[poz3.first - 2][poz3.second] == 0 && viz[poz3.first - 1][poz3.second] == 0)
cate++;
}
if (cate == 2 || cate == 3)
return 0;
else
{
if (!(poz1.first + 2 > n))
{
if (v[poz1.first + 1][poz1.second] == 'G' && v[poz1.first + 2][poz1.second] == 'W' && viz[poz1.first + 1][poz1.second] == 0 && viz[poz1.first + 2][poz1.second] == 0)
{
cate++;
viz[poz1.first + 1][poz1.second] = 1;
viz[poz1.first + 2][poz1.second] = 1;
}
}
if (!(poz2.first - 1 < 0 || poz2.first + 1 > n))
{
if (v[poz2.first - 1][poz2.second] == 'R' && v[poz2.first + 1][poz2.second] == 'W' && viz[poz2.first - 1][poz2.second] == 0 && viz[poz2.first + 1][poz2.second] == 0)
{
cate++;
viz[poz2.first - 1][poz2.second] = 1;
viz[poz2.first + 1][poz2.second] = 1;
}
}
if (!(poz2.first - 2 < 0))
{
if (v[poz3.first - 2][poz3.second] == 'R' && v[poz3.first - 1][poz3.second] == 'G' && viz[poz3.first - 2][poz3.second] == 0 && viz[poz3.first - 1][poz3.second] == 0)
{
cate++;
viz[poz3.first - 2][poz3.second] = 1;
viz[poz3.first - 1][poz3.second] = 1;
}
}
return 1;
}
}
bool ok_col (pair<int, int> poz1, pair<int, int> poz2, pair<int, int> poz3)
{
if (viz[poz1.first][poz1.second] == 1 || viz[poz2.first][poz2.second] == 1 || viz[poz3.first][poz3.second] == 1)
return false;
if (v[poz1.first][poz1.second] == 'R' && v[poz2.first][poz2.second] == 'G' && v[poz3.first][poz3.second] == 'W')
return true;
return false;
}
void solve ()
{
cin >> n >> m;
for (int i = 1;i<=n;++i)
for (int j = 1;j<=m;++j)
{
char a;
cin >> a;
v[i][j] = a;
}
int ans = 0;
for (int i = 1;i <= n;++i)
for (int j = 1;j<=m - 2;++j)
{
pair <int, int> poz1 = {i,j};
pair <int, int> poz2 = {i,j+1};
pair <int, int> poz3 = {i,j+2};
if (ok_lin (poz1, poz2, poz3))
{
ans++;
viz[poz1.first][poz1.second] = 1;
viz[poz2.first][poz2.second] = 1;
viz[poz3.first][poz3.second] = 1;
}
}
for (int j = 1;j<=m;++j)
for (int i = 1;i<=n-2;++i)
{
pair <int, int> poz1 = {i, j};
pair <int, int> poz2 = {i+1, j};
pair <int, int> poz3 = {i+2, j};
if (ok_col (poz1, poz2, poz3))
{
ans++;
viz[poz1.first][poz1.second] = 1;
viz[poz2.first][poz2.second] = 1;
viz[poz3.first][poz3.second] = 1;
}
}
cout << ans << '\n';
}
main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while (t--)
solve();
}
Compilation message (stderr)
dango_maker.cpp:128:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
128 | main ()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |