# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79761 | antimirage | Dango Maker (JOI18_dango_maker) | C++17 | 217 ms | 71376 KiB |
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 pb emplace_back
using namespace std;
const int N = 3005;
int n, m, d[2][N][N], sz, u[3000005], wh, bl, ans;
char ar[N][N];
vector <int> g[3000005];
void dfs (int v, int color)
{
if (color == 0) wh++;
else bl++;
u[v] = 1;
for (auto to : g[v])
{
if (!u[to])
dfs(to, color ^ 1);
}
}
main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
scanf("\n");
for (int j = 1; j <= m; j++)
scanf("%c", &ar[i][j]);
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if ( j + 2 <= m && ar[i][j] == 'R' && ar[i][j + 1] == 'G' && ar[i][j + 2] == 'W' )
d[0][i][j] = ++sz;
if ( i + 2 <= n && ar[i][j] == 'R' && ar[i + 1][j] == 'G' && ar[i + 2][j] == 'W')
d[1][i][j] = ++sz;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if ( d[0][i][j] )
{
if (d[1][i][j])
g[ d[0][i][j] ].pb( d[1][i][j] ),
g[ d[1][i][j] ].pb( d[0][i][j] );
if (d[1][i - 1][j + 1])
g[ d[0][i][j] ].pb( d[1][i - 1][j + 1] ),
g[ d[1][i - 1][j + 1] ].pb( d[0][i][j] );
if (d[1][i - 2][j + 2])
g[ d[0][i][j] ].pb( d[1][i - 2][j + 2] ),
g[ d[1][i - 2][j + 2] ].pb( d[0][i][j] );
}
if ( d[1][i][j] )
{
if (d[0][i][j])
g[ d[1][i][j] ].pb( d[0][i][j] ),
g[ d[0][i][j] ].pb( d[1][i][j] );
if (d[0][i + 1][j - 1])
g[ d[0][i + 1][j - 1] ].pb( d[1][i][j] ),
g[ d[1][i][j] ].pb( d[0][i + 1][j - 1] );
if (d[0][i + 2][j - 2])
g[ d[0][i + 2][j - 2] ].pb( d[1][i][j] ),
g[ d[1][i][j] ].pb( d[0][i + 2][j - 2] );
}
}
}
for (int i = 1; i <= sz; i++)
{
if (u[i]) continue;
wh = bl = 0;
dfs(i, 0);
ans += max( wh, bl );
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |