Submission #103046

#TimeUsernameProblemLanguageResultExecution timeMemory
103046tincamateiDango Maker (JOI18_dango_maker)C++14
13 / 100
215 ms211964 KiB
#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)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:41:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d", &n, &m);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...