Submission #544978

#TimeUsernameProblemLanguageResultExecution timeMemory
544978valerikkLand of the Rainbow Gold (APIO17_rainbow)C++17
11 / 100
4 ms864 KiB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 55;

int n, m;
int a[N][N];
int cnt;

void init(int R, int C, int sr, int sc, int M, char *S) {
	n = R;
	m = C;
	
	for (int i = 0; i < n; ++i) {
		fill_n(a[i], m, 0);
	}
	
	int x = sr - 1, y = sc - 1;
	a[x][y] = 1;
	cnt = 1;
	for (int i = 0; i < M; ++i) {
		if (S[i] == 'N') {
			--x;
		}
		if (S[i] == 'S') {
			++x;
		}
		if (S[i] == 'E') {
			++y;
		}
		if (S[i] == 'W') {
			--y;
		}

		cnt += !a[x][y];
	
		a[x][y] = 1;
	}
}

int colour(int ar, int ac, int br, int bc) {
	int x1 = ar - 1, y1 = ac - 1, x2 = br - 1, y2 = bc - 1;
	
	int e = 0, v = 0, f = 0;
	for (int x = x1; x <= x2; ++x) {
		for (int y = y1; y <= y2; ++y) {
			e += x < x2 && !a[x][y] && !a[x + 1][y];
			e += y < y2 && !a[x][y] && !a[x][y + 1];
			v += !a[x][y];
			f += x < x2 && y < y2 && !a[x][y] && !a[x + 1][y] && !a[x][y + 1] && !a[x + 1][y + 1];
		}
	}

	{
		int cn = 0;
		for (int x = x1 + 1; x <= x2 - 1; ++x) {
			for (int y = y1 + 1; y <= y2 - 1; ++y) {
				cn += a[x][y];
			}
		}	
		f += cn == cnt;
	}

	if (v == 0) {
		return 0;
	}

	int c = f - e + v;

	return c;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...