# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153408 | mhy908 | Dango Maker (JOI18_dango_maker) | C++14 | 80 ms | 70928 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 F first
#define S second
#define pb push_back
#define llinf 987654321987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m, x;
char str[3010][3010];
int col[3010][3010][3], re[3010][3010], ans;
vector<int> link[3000010];
int ishere[3000010];
int onenum, twonum;
void dfs(int here, int c)
{
if(ishere[here])return;
ishere[here]=c;
if(c==1)onenum++;
else twonum++;
for(int i=0; i<link[here].size(); i++){
dfs(link[here][i], c==1?2:1);
}
}
int main()
{
scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
scanf(" %c", &str[i][j]);
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(str[i][j]=='R'&&str[i][j+1]=='G'&&str[i][j+2]=='W'){
++x;
col[i][j][++re[i][j]]=x;
col[i][j+1][++re[i][j+1]]=x;
col[i][j+2][++re[i][j+2]]=x;
}
if(str[i][j]=='R'&&str[i+1][j]=='G'&&str[i+2][j]=='W'){
++x;
col[i][j][++re[i][j]]=x;
col[i+1][j][++re[i+1][j]]=x;
col[i+2][j][++re[i+2][j]]=x;
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(re[i][j]==2){
link[col[i][j][1]].pb(col[i][j][2]);
link[col[i][j][2]].pb(col[i][j][1]);
}
}
}
for(int i=1; i<=x; i++){
if(ishere[i])continue;
onenum=twonum=0;
dfs(i, 1);
ans+=max(onenum, twonum);
}
printf("%d", ans);
}
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... |