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 "rainbow.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<bool> used[2009]; int H, W, minx = (1 << 30), miny = (1 << 30), maxx = 0, maxy = 0;
vector<int> A[4][2009], A2[2009], A3[2009], A4[2009];
void init(int R, int C, int sr, int sc, int M, char *S) {
H = R; W = C;
for (int i = 0; i <= H; i++) used[i].resize(W + 1, true);
for (int i = 0; i <= H; i++) { for (int j = 0; j < 4; j++) A[j][i].resize(W + 1, 0); }
int cx = sr, cy = sc; used[cx][cy] = false; minx = cx; miny = cy; maxx = cx; maxy = cy;
for (int i = 0; i < M; i++) {
if (S[i] == 'E') cy++;
if (S[i] == 'W') cy--;
if (S[i] == 'N') cx--;
if (S[i] == 'S') cx++;
used[cx][cy] = false;
minx = min(minx, cx); maxx = max(maxx, cx);
miny = min(miny, cy); maxy = max(maxy, cy);
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) { if (used[i][j] == true) A[0][i][j] = 1; }
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W - 1; j++) { if (used[i][j] == true && used[i][j + 1] == true) A[1][i][j] = 1; }
}
for (int i = 1; i <= H - 1; i++) {
for (int j = 1; j <= W; j++) { if (used[i][j] == true && used[i + 1][j] == true) A[2][i][j] = 1; }
}
for (int i = 1; i <= H - 1; i++) {
for (int j = 1; j <= W - 1; j++) { if (used[i][j] == true && used[i][j + 1] == true && used[i + 1][j] == true && used[i + 1][j + 1] == true) A[3][i][j] = 1; }
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j <= H; j++) {
for (int k = 1; k <= W; k++) A[i][j][k] += A[i][j][k - 1];
}
for (int j = 1; j <= H; j++) {
for (int k = 0; k <= W; k++) A[i][j][k] += A[i][j - 1][k];
}
}
}
int ranged(int ty, int px, int py, int qx, int qy) {
if (px > qx || py > qy) return 0;
return A[ty][px - 1][py - 1] + A[ty][qx][qy] - A[ty][px - 1][qy] - A[ty][qx][py - 1];
}
int colour(int ar, int ac, int br, int bc) {
int Z1 = ranged(0, ar, ac, br, bc);
int Z2 = ranged(1, ar, ac, br, bc - 1);
int Z3 = ranged(2, ar, ac, br - 1, bc);
int Z4 = ranged(3, ar, ac, br - 1, bc - 1);
int BONUS = 0; if (ar < minx && maxx < br && ac < miny && maxy < bc) BONUS = 1;
return (Z1 - Z2 - Z3 + Z4 + BONUS);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |