#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
typedef long ll;
typedef pair<ll, ll> pp;
#define MAX 101010
#define INF 10000000
#define pb push_back
vector<pp> V;
set<pp> s, vs;
vector<pp> dir;
pp operator+(pp a, pp b) {
return { a.first + b.first, a.second + b.second };
}
bool exist(pp x) {
return !(s.find(x) == s.end());
}
void init(int R, int C, int sr, int sc, int M, char *S) {
ll i;
ll x, y;
dir.pb({ 1, 0 });
dir.pb({ 0, 1 });
dir.pb({ -1, 0 });
dir.pb({ 0, -1 });
x = sr;
y = sc;
s.insert({ x, y });
for (i = 0; i < M; i++) {
if (S[i] == 'N') s.insert({ --x, y });
if (S[i] == 'S') s.insert({ ++x, y });
if (S[i] == 'W') s.insert({ x, --y });
if (S[i] == 'E') s.insert({ x, ++y });
}
set<pp>::iterator it;
for (it = s.begin(); it != s.end(); it++) V.pb(*it);
}
int colour(int ar, int ac, int br, int bc) {
s.clear();
vs.clear();
ll M = V.size();
ll i, j;
ll v, e, r;
v = e = r = 0;
ll c;
for (i = ar; i <= br; i++) s.insert({ i, ac - 1 }), s.insert({ i, bc + 1 });
for (i = ac; i <= bc; i++) s.insert({ ar - 1, i }), s.insert({ br + 1, i });
for (i = 0; i < M; i++) {
if (!((ar <= V[i].first&&V[i].first <= br) && (ac <= V[i].second&&V[i].second <= bc))) continue;
if (exist(V[i])) continue;
s.insert(V[i]);
r++;
for (j = 0; j < 4; j++) if (!exist(V[i] + dir[j])) e++;
for (j = 0; j < 4; j++) if (!(exist(V[i] + dir[j]) || exist(V[i] + dir[(j + 1) % 4]) || exist(V[i] + dir[j] + dir[(j + 1) % 4]))) v++;
}
v += 2 * (bc - ac + br - ar + 2);
e += 2 * (bc - ac + br - ar + 2);
return e - v - r + 1;
}
Compilation message
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:44:5: warning: unused variable 'c' [-Wunused-variable]
44 | ll c;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
77 ms |
492 KB |
Output is correct |
3 |
Incorrect |
29 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Execution timed out |
3075 ms |
27752 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
231 ms |
24028 KB |
Output is correct |
3 |
Correct |
188 ms |
24028 KB |
Output is correct |
4 |
Correct |
238 ms |
20956 KB |
Output is correct |
5 |
Correct |
110 ms |
11744 KB |
Output is correct |
6 |
Correct |
152 ms |
31848 KB |
Output is correct |
7 |
Incorrect |
283 ms |
45928 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
77 ms |
492 KB |
Output is correct |
3 |
Incorrect |
29 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
364 KB |
Output is correct |
2 |
Correct |
77 ms |
492 KB |
Output is correct |
3 |
Incorrect |
29 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |