//By Don4ick
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = 3005;
const int M = N * N * 2;
using namespace std;
bitset < M > was;
int n, m, cnt0, cnt1;
string s[N];
void dfs(int x, int y, int type)
{
int v = x * m + y + type * n * m;
was[v] = true;
if (type == 0)
{
cnt0++;
if (x < n - 2 && s[x + 1][y] == 'G' && s[x + 2][y] == 'W')
{
int u = x * m + y + n * m;
if (!was[u])
dfs(x, y, 1);
}
if (x < n - 1 && x > 0 && s[x - 1][y + 1] == 'R' && s[x + 1][y + 1] == 'W')
{
int tx = x - 1, ty = y + 1;
int u = tx * m + ty + n * m;
if (!was[u])
dfs(tx, ty, 1);
}
if (x > 1 && s[x - 2][y + 2] == 'R' && s[x - 1][y + 2] == 'G')
{
int tx = x - 2, ty = y + 2;
int u = tx * m + ty + n * m;
if (!was[u])
dfs(tx, ty, 1);
}
}
else
{
cnt1++;
if (y < n - 2 && s[x][y + 1] == 'G' && s[x][y + 2] == 'W')
{
int tx = x, ty = y;
int u = tx * m + ty;
if (!was[u])
dfs(tx, ty, 0);
}
if (y < n - 1 && y > 0 && s[x + 1][y - 1] == 'R' && s[x + 1][y + 1] == 'W')
{
int tx = x + 1, ty = y - 1;
int u = tx * m + ty;
if (!was[u])
dfs(tx, ty, 0);
}
if (y > 1 && s[x + 2][y - 2] == 'R' && s[x + 2][y - 1] == 'G')
{
int tx = x + 2, ty = y - 2;
int u = tx * m + ty;
if (!was[u])
dfs(tx, ty, 0);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
//~read
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> s[i];
//~solve
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m - 2; j++)
{
int v = i * m + j;
if (s[i][j] == 'R' && s[i][j + 1] == 'G' && s[i][j + 2] == 'W' && !was[v])
{
cnt0 = cnt1 = 0;
dfs(i, j, 0);
ans += max(cnt0, cnt1);
}
}
}
for (int i = 0; i < n - 2; i++)
{
for (int j = 0; j < m; j++)
{
int v = i * m + j + n * m;
if (s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i + 2][j] == 'W' && !was[v])
{
cnt0 = cnt1 = 0;
dfs(i, j, 1);
ans += max(cnt0, cnt1);
}
}
}
//~result
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
3 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
3 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
760 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
3 ms |
760 KB |
Output is correct |
20 |
Correct |
4 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
760 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
760 KB |
Output is correct |
24 |
Correct |
2 ms |
760 KB |
Output is correct |
25 |
Correct |
3 ms |
760 KB |
Output is correct |
26 |
Correct |
4 ms |
760 KB |
Output is correct |
27 |
Correct |
3 ms |
760 KB |
Output is correct |
28 |
Correct |
3 ms |
760 KB |
Output is correct |
29 |
Correct |
2 ms |
760 KB |
Output is correct |
30 |
Correct |
2 ms |
760 KB |
Output is correct |
31 |
Correct |
3 ms |
760 KB |
Output is correct |
32 |
Correct |
3 ms |
760 KB |
Output is correct |
33 |
Correct |
3 ms |
760 KB |
Output is correct |
34 |
Incorrect |
2 ms |
760 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
3 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
3 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
760 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
3 ms |
760 KB |
Output is correct |
20 |
Correct |
4 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
760 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
760 KB |
Output is correct |
24 |
Correct |
2 ms |
760 KB |
Output is correct |
25 |
Correct |
3 ms |
760 KB |
Output is correct |
26 |
Correct |
4 ms |
760 KB |
Output is correct |
27 |
Correct |
3 ms |
760 KB |
Output is correct |
28 |
Correct |
3 ms |
760 KB |
Output is correct |
29 |
Correct |
2 ms |
760 KB |
Output is correct |
30 |
Correct |
2 ms |
760 KB |
Output is correct |
31 |
Correct |
3 ms |
760 KB |
Output is correct |
32 |
Correct |
3 ms |
760 KB |
Output is correct |
33 |
Correct |
3 ms |
760 KB |
Output is correct |
34 |
Incorrect |
2 ms |
760 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |