Submission #403094

# Submission time Handle Problem Language Result Execution time Memory
403094 2021-05-12T18:15:22 Z BERNARB01 Land of the Rainbow Gold (APIO17_rainbow) C++17
11 / 100
3000 ms 15440 KB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1002;
const int maxN = (int) 2e5 + 9;

int sub = 1;

int a[N][N], vis[N][N], done[N][N], u, l, d, r, sum1[maxN], sum2[maxN], sum12[maxN], vis2[2][maxN];

array<int, 4> di = {0, 0, 1, -1};
array<int, 4> dj = {1, -1, 0, 0};


bool valid(int i, int j) {
	return (u <= i && i <= d && l <= j && j <= r && !vis[i][j] && !done[i][j]);
}

void dfs(int i, int j) {
	done[i][j] = 1;
	for (int k = 0; k < 4; k++) {
		int ni = i + di[k];
		int nj = j + dj[k];
		if (valid(ni, nj)) {
			dfs(ni, nj);
		}
	}
}

int isNew(int i) {
	if ((vis2[0][i] + vis2[1][i] < 2) && (vis2[0][i - 1] && vis2[1][i - 1])) {
		// 10    11   10
		// 11    10   10
		return 1;
	}
	if ((vis2[0][i] + !vis2[1][i] == 1) && vis2[0][i] != vis2[0][i - 1] && vis2[1][i] != vis2[1][i - 1]) {
		// 01    10
		// 10    01
		return 1;
	}
	return 0;
}

void init(int R, int C, int sr, int sc, int M, char *S) {
	if (R == 2 && C > 50) {
		sub = 2;
	}
	u = 1; d = R;
	l = 1; r = C;
	if (sub == 2) {
		vis2[sr][sc] = 1;
	} else {
		vis[sr][sc] = 1;
	}
	for (int i = 0; i < M; i++) {
		if (S[i] == 'N') {
			sr--;
		} else if (S[i] == 'S') {
			sr++;
		} else if (S[i] == 'E') {
			sc++;
		} else {
			sc--;
		}
		if (sub == 2) {
			vis2[sr][sc] = 1;
		} else {
			vis[sr][sc] = 1;
		}
	}
	if (sub == 2) {
		vis2[0][0] = vis2[1][0] = 1;
		for (int i = 1; i <= C; i++) {
			sum1[i] = sum1[i - 1] + !vis2[0][i];
			sum2[i] = sum2[i - 1] + !vis2[1][i];
			sum12[i] = sum12[i - 1] + isNew(i);
		}
	}
}

int colour(int ar, int ac, int br, int bc) {
	u = ar; d = br;
	l = ac; r = bc;
	int ans = 0;
	if (sub == 2) {
		if (u == d) {
			if (d == 1) {
				return sum1[r] - sum1[l - 1];
			} else {
				return sum2[r] - sum2[l - 1];
			}
		} else {
			return (sum12[r] - sum12[l - 1]) + ((vis2[0][l] + vis2[1][l] < 2) && !isNew(l));
		}
	}
	for (int i = u; i <= d; i++) {
		for (int j = l; j <= r; j++) {
			if (!vis[i][j] && !done[i][j]) {
				dfs(i, j);
				ans++;
			}
		}
	}
	memset(done, 0, sizeof done);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 144 ms 4308 KB Output is correct
2 Correct 146 ms 4428 KB Output is correct
3 Correct 167 ms 4556 KB Output is correct
4 Correct 162 ms 4528 KB Output is correct
5 Correct 146 ms 4440 KB Output is correct
6 Correct 3 ms 4172 KB Output is correct
7 Correct 3 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 3 ms 4172 KB Output is correct
10 Correct 3 ms 4172 KB Output is correct
11 Correct 164 ms 4464 KB Output is correct
12 Correct 151 ms 4492 KB Output is correct
13 Correct 152 ms 4480 KB Output is correct
14 Correct 144 ms 4428 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 4 ms 4172 KB Output is correct
17 Correct 4 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4172 KB Output is correct
2 Correct 4 ms 4172 KB Output is correct
3 Incorrect 61 ms 3860 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Runtime error 2 ms 588 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 144 ms 4308 KB Output is correct
2 Correct 146 ms 4428 KB Output is correct
3 Correct 167 ms 4556 KB Output is correct
4 Correct 162 ms 4528 KB Output is correct
5 Correct 146 ms 4440 KB Output is correct
6 Correct 3 ms 4172 KB Output is correct
7 Correct 3 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 3 ms 4172 KB Output is correct
10 Correct 3 ms 4172 KB Output is correct
11 Correct 164 ms 4464 KB Output is correct
12 Correct 151 ms 4492 KB Output is correct
13 Correct 152 ms 4480 KB Output is correct
14 Correct 144 ms 4428 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 4 ms 4172 KB Output is correct
17 Correct 4 ms 4172 KB Output is correct
18 Execution timed out 3093 ms 15440 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 144 ms 4308 KB Output is correct
2 Correct 146 ms 4428 KB Output is correct
3 Correct 167 ms 4556 KB Output is correct
4 Correct 162 ms 4528 KB Output is correct
5 Correct 146 ms 4440 KB Output is correct
6 Correct 3 ms 4172 KB Output is correct
7 Correct 3 ms 4172 KB Output is correct
8 Correct 3 ms 4172 KB Output is correct
9 Correct 3 ms 4172 KB Output is correct
10 Correct 3 ms 4172 KB Output is correct
11 Correct 164 ms 4464 KB Output is correct
12 Correct 151 ms 4492 KB Output is correct
13 Correct 152 ms 4480 KB Output is correct
14 Correct 144 ms 4428 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 4 ms 4172 KB Output is correct
17 Correct 4 ms 4172 KB Output is correct
18 Execution timed out 3093 ms 15440 KB Time limit exceeded
19 Halted 0 ms 0 KB -