Submission #732401

# Submission time Handle Problem Language Result Execution time Memory
732401 2023-04-29T03:38:54 Z SanguineChameleon Land of the Rainbow Gold (APIO17_rainbow) C++17
0 / 100
504 ms 1048576 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;

struct BIT {
	set<pair<int, int>> S;
	vector<vector<int>> a;
	int R, C;

	void init(int _R, int _C) {
		R = _R;
		C = _C;
		a.resize(R + 1);
		for (int i = 0; i <= R; i++) {
			a[i].resize(C + 1);
		}
	}

	void add(int x, int y) {
		if (x < 0 || x > R || y < 0 || y > C || S.find({x, y}) != S.end()) {
			return;
		}
		S.insert({x, y});
		a[x][y]++;
	}

	void build() {
		for (int i = 1; i <= R; i++) {
			for (int j = 1; j <= C; j++) {
				a[i][j] += a[i][j - 1];
			}
		}
		for (int j = 1; j <= C; j++) {
			for (int i = 1; i <= R; i++) {
				a[i][j] += a[i - 1][j];
			}
		}
	}

	int get(int x, int y) {
		return a[x][y];
	}

	int get(int lx, int ly, int rx, int ry) {
		return (rx - lx + 1) * (ry - ly + 1) - get(rx, ry) + get(rx, ly - 1) + get(lx - 1, ry) - get(lx - 1, ly - 1);
	}

} V, row_E, col_E, F;

void add(int cx, int cy) {
	V.add(cx, cy);
	row_E.add(cx - 1, cy);
	row_E.add(cx, cy);
	col_E.add(cx, cy - 1);
	col_E.add(cx, cy);
	F.add(cx - 1, cy - 1);
	F.add(cx - 1, cy);
	F.add(cx, cy - 1);
	F.add(cx, cy);
}

void init(int R, int C, int cx, int cy, int M, char *S) {
	V.init(R, C);
	row_E.init(R, C);
	col_E.init(R, C);
	F.init(R, C);
	add(cx, cy);
	for (int i = 0; i < M; i++) {
		if (S[i] == 'N') {
			cx--;
		}
		if (S[i] == 'E') {
			cy++;
		}
		if (S[i] == 'S') {
			cx++;
		}
		if (S[i] == 'W') {
			cy--;
		}
		add(cx, cy);
	}
	V.build();
	row_E.build();
	col_E.build();
	F.build();
}

int colour(int lx, int ly, int rx, int ry) {
	return V.get(lx, ly, rx, ry) - row_E.get(lx, ly, rx - 1, ry) - col_E.get(lx, ly, rx, ry - 1) + F.get(lx, ly, rx - 1, ry - 1);
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 504 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 300 KB Output isn't correct
2 Halted 0 ms 0 KB -