# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
70182 | 3zp | Dango Maker (JOI18_dango_maker) | C++14 | 155 ms | 141960 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 maxn 500009
using namespace std;
string s[3009];
int A[3009][3009];
int B[3009][3009];
int a[3009][3009];
int b[3009][3009];
int k, Bl, Wi;
vector<int> v[6000009];
int f[6000009];
void dfs(int x, int c){
f[x] = 1;
if(c == 1) Wi++;
else Bl++;
for(int i = 0; i < v[x].size(); i++)
if(!f[v[x][i]])dfs(v[x][i], 1 - c);
}
main(){
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> s[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(j + 2 < m && s[i][j] == 'R'
&& s[i][j+1] == 'G'
&& s[i][j+2] == 'W')
A[i][j] = 1, a[i][j] = ++k;
if(i + 2 < n && s[i][j] == 'R'
&& s[i+1][j] == 'G'
&& s[i+2][j] == 'W')
B[i][j] = 1, b[i][j] = ++k;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(A[i][j])
{ if (i >= 1 && B[i-1][j+1])
{
v[a[i][j]].push_back(b[i-1][j+1]);
v[b[i-1][j+1]].push_back(a[i][j]);
}
if(i >= 2 && B[i-2][j+2]){
v[a[i][j]].push_back(b[i-2][j+2]);
v[b[i-2][j+2]].push_back(a[i][j]);
}
if(B[i][j]){
v[a[i][j]].push_back(b[i][j]);
v[b[i][j]].push_back(a[i][j]);
}
}
}
}
int ans = 0;
for(int i = 1; i <= k; i++){
if(f[i] == 0){
Bl = 0;
Wi = 0;
dfs(i, 0);
ans += max(Bl,Wi);
}
}
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... |