#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
#define ll long long
#define fi first
#define se second
ll inf = 1ll << 60;
int r, c, m, q, r0, c0, r1, c1, r2, c2;
char *s;
map<pair<int, int>, bool> is, is2, vis;
bool valid(int i, int j){
if (i > r2 or i < r1) return false;
if (j > c2 or j < c1) return false;
if (is[{i, j}]) return false;
return true;
}
void dfs(int i, int j){
vis[{i, j}] = true;
if (is2[{i + 1, j}] and !vis[{i + 1, j}]) dfs(i + 1, j);
if (is2[{i - 1, j}] and !vis[{i - 1, j}]) dfs(i - 1, j);
if (is2[{i, j + 1}] and !vis[{i, j + 1}]) dfs(i, j + 1);
if (is2[{i, j - 1}] and !vis[{i, j - 1}]) dfs(i, j - 1);
}
void init(int _r, int _c, int _r0, int _c0, int _m, char *_s){
r = _r, c = _c, m = _m, r0 = _r0, c0 = _c0, s = _s;
}
int colour(int _r1, int _c1, int _r2, int _c2){
r1 = _r1, c1 = _c1, r2 = _r2, c2 = _c2;
vector<pair<int, int>> a, b, c;
a.push_back({r0, c0});
int x = r0, y = c0;
for (int i = 0; i < m; i++){
if (s[i] == 'S') x++;
if (s[i] == 'N') x--;
if (s[i] == 'E') y++;
if (s[i] == 'W') y--;
if (valid(x, y)) a.push_back({x, y});
is[{x, y}] = true;
}
for (int i = r1; i <= r2; i++){
c.push_back({i, c1 - 1});
c.push_back({i, c2 + 1});
}
for (int i = c1; i <= c2; i++){
c.push_back({r1 - 1, i});
c.push_back({r2 + 1, i});
}
for (auto i : a){
if (valid(i.fi + 1, i.se)) b.push_back({i.fi + 1, i.se});
if (valid(i.fi, i.se + 1)) b.push_back({i.fi, i.se + 1});
if (valid(i.fi - 1, i.se)) b.push_back({i.fi - 1, i.se});
if (valid(i.fi, i.se - 1)) b.push_back({i.fi, i.se - 1});
}
bool has = 0;
for (auto i : b){
if (i.fi <= r1 + 1 or i.fi >= r2 - 1 or i.se <= c1 + 1 or i.se >= c2 - 1){
has = 1;
}
}
int ans = 0;
if (!has and !b.empty()) ans--;
for (auto i : c){
if (valid(i.fi + 1, i.se)) b.push_back({i.fi + 1, i.se});
if (valid(i.fi, i.se + 1)) b.push_back({i.fi, i.se + 1});
if (valid(i.fi - 1, i.se)) b.push_back({i.fi - 1, i.se});
if (valid(i.fi, i.se - 1)) b.push_back({i.fi, i.se - 1});
}
for (auto i : b) is2[i] = true;
for (auto i : b){
if (!vis[i]){
dfs(i.fi, i.se);
ans++;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |