#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int N = 100;
char table[N][N];
int n, m;
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R, m = C;
table[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] == 'W') {
sc--;
} else {
sc++;
}
table[sr][sc] = 1;
}
}
bool is_valid(int x, int y, int lx, int rx, int ly, int ry) {
return x >= lx && x <= rx && y >= ly && y <= ry;
}
bool value(int x, int y, int lx, int rx, int ly, int ry) {
return x < lx || x > rx || y < ly || y > ry || table[x][y];
}
int colour(int ar, int ac, int br, int bc) {
bool found = false;
for (int i = ar; i <= br; i++) {
for (int j = ac; j <= bc; j++) {
if (table[i][j]) {
ar = i;
found = true;
break;
}
}
if (found) {
break;
}
}
if (!found) {
return 1;
}
int e = 0, v = 0;
int e_border = 0;
for (int i = ar; i <= br; i++) {
for (int j = ac; j <= bc; j++) {
if (table[i][j]) {
v++;
for (int k = 0; k < 4; k++) {
int ni = i + dx[k];
int nj = j + dy[k];
if (is_valid(ni, nj, ar, br, ac, bc) && table[ni][nj]) {
e++;
} else if (value(ni, nj, ar, br, ac, bc)) {
e_border++;
}
}
}
}
}
e /= 2;
v += 2 * (br - ar + 1 + bc - ac + 1) + 4;
e += 2 * (br - ar + 1 + bc - ac + 1) + 4;
e += e_border;
// return e;
int sub = 0;
for (int i = ar - 1; i <= br; i++) {
for (int j = ac - 1; j <= bc; j++) {
sub += value(i, j, ar, br, ac, bc) & value(i + 1, j, ar, br, ac, bc) & value(i + 1, j + 1, ar, br, ac, bc) & value(i, j + 1, ar, br, ac, bc);
}
}
return e - v + 1 - sub;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
2 ms |
700 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |