#include <bits/stdc++.h>
using namespace std;
#include "rainbow.h"
set<pair<int, int>> relevantes;
set<pair<int, int>> agua;
int dx[] = {1,-1,0,0,1,-1,1,-1};
int dy[] = {0,0,1,-1,1,1,-1,-1};
void dfs(int x, int y, set<pair<int, int>> &marc, int ar, int ac, int br, int bc)
{
marc.emplace(x, y);
// cerr << x << " " << y << " ok " << '\n';
for (int k = 0; k < 4; k++)
{
int hx = x + dx[k], hy = y + dy[k];
if (hx < ar || hy < ac || hx > br || hy > bc) continue;
if (agua.count(make_pair(hx, hy)) || marc.count(make_pair(hx, hy))) continue;
dfs(hx, hy, marc, ar, ac, br, bc);
}
}
void init(int R, int C, int sr, int sc, int M, char *S)
{
agua.emplace(sr, sc); relevantes.emplace(sr, sc);
for (int k = 0; k < 8; k++) relevantes.emplace(sr+dx[k], sc+dy[k]);
// cerr << "snake: " << '\n';
// cerr << "sr: " << sr << ", sc: " << sc << '\n';
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--;
agua.emplace(sr, sc); relevantes.emplace(sr, sc);
// cerr << "sr: " << sr << ", sc: " << sc << '\n';
for (int k = 0; k < 8; k++) relevantes.emplace(sr+dx[k], sc+dy[k]);
}
}
int colour(int ar, int ac, int br, int bc)
{
set<pair<int, int>> marc; int numAgua = 0; int resp = 0;
for (auto [x, y] : relevantes)
{
if (x < ar || y < ac || x > br || y > bc) continue;
if (agua.count(make_pair(x, y))) {numAgua++; continue;}
if (marc.count(make_pair(x, y))) continue;
dfs(x, y, marc, ar, ac, br, bc); resp++;
// cerr << "thats comp" << '\n';
}
// cerr << "numAgua: " << numAgua << '\n';
if (numAgua == 0) return 1;
return resp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
336 KB |
Output is correct |
2 |
Correct |
102 ms |
660 KB |
Output is correct |
3 |
Correct |
187 ms |
848 KB |
Output is correct |
4 |
Correct |
208 ms |
756 KB |
Output is correct |
5 |
Correct |
98 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
187 ms |
732 KB |
Output is correct |
12 |
Correct |
169 ms |
736 KB |
Output is correct |
13 |
Correct |
175 ms |
772 KB |
Output is correct |
14 |
Correct |
96 ms |
688 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Execution timed out |
3067 ms |
62024 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Runtime error |
2716 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
336 KB |
Output is correct |
2 |
Correct |
102 ms |
660 KB |
Output is correct |
3 |
Correct |
187 ms |
848 KB |
Output is correct |
4 |
Correct |
208 ms |
756 KB |
Output is correct |
5 |
Correct |
98 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
187 ms |
732 KB |
Output is correct |
12 |
Correct |
169 ms |
736 KB |
Output is correct |
13 |
Correct |
175 ms |
772 KB |
Output is correct |
14 |
Correct |
96 ms |
688 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Execution timed out |
3067 ms |
46880 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
336 KB |
Output is correct |
2 |
Correct |
102 ms |
660 KB |
Output is correct |
3 |
Correct |
187 ms |
848 KB |
Output is correct |
4 |
Correct |
208 ms |
756 KB |
Output is correct |
5 |
Correct |
98 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
504 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
187 ms |
732 KB |
Output is correct |
12 |
Correct |
169 ms |
736 KB |
Output is correct |
13 |
Correct |
175 ms |
772 KB |
Output is correct |
14 |
Correct |
96 ms |
688 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Execution timed out |
3067 ms |
46880 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |