# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103046 | tincamatei | Dango Maker (JOI18_dango_maker) | C++14 | 215 ms | 211964 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>
using namespace std;
const int MAX_N = 3000;
const int MAX_GRAPH = MAX_N * MAX_N;
char getch(FILE *fin) {
char ch = fgetc(fin);
while(!isalpha(ch))
ch = fgetc(fin);
return ch;
}
int top;
vector<int> graph[1+MAX_GRAPH];
bool viz[1+MAX_GRAPH];
int edge[MAX_N][MAX_N];
char matr[MAX_N][MAX_N];
void dfs(int nod, int color, int *r) {
r[color]++;
viz[nod] = true;
for(auto it: graph[nod])
if(!viz[it])
dfs(it, 1 - color, r);
}
int main() {
#ifdef HOME
FILE *fin = fopen("input.in", "r");
FILE *fout = fopen("output.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int n, m;
int rez = 0;
fscanf(fin, "%d%d", &n, &m);
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j)
matr[i][j] = getch(fin);
for(int i = 0; i < n; ++i)
for(int j = 0; j < m - 2; ++j) {
if(matr[i][j] == 'R' && matr[i][j + 1] == 'G' && matr[i][j + 2] == 'W') {
++top;
edge[i][j] = edge[i][j + 1] = edge[i][j + 2] = top;
}
}
for(int i = 0; i < n - 2; ++i)
for(int j = 0; j < m; ++j) {
if(matr[i][j] == 'R' && matr[i + 1][j] == 'G' && matr[i + 2][j] == 'W') {
++top;
for(int x = 0; x < 3; ++x)
if(edge[i + x][j] != 0) {
graph[top].push_back(edge[i + x][j]);
graph[edge[i + x][j]].push_back(top);
}
}
}
for(int i = 1; i <= top; ++i) {
if(!viz[i]) {
int r[2];
r[0] = r[1] = 0;
dfs(i, 0, r);
rez = rez + max(r[0], r[1]);
}
}
fprintf(fout, "%d", rez);
fclose(fin);
fclose(fout);
return 0;
}
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... |