#include "rainbow.h"
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct UF {
vector<int> U, R;
int C;
UF(int N) {
rep(i, N) U.pb(i), R.pb(1);
C = N;
}
int find(int x) {
if (U[x]==x)return x;
return U[x]=find(U[x]);
}
void unite(int x, int y) {
x=find(x), y=find(y);
if (x==y)return;
if (R[x]<R[y])swap(x,y);
U[y]=x;
R[x]+=R[y];
C--;
}
};
bool bad[50][50];
int id[50][50];
void init(int H, int W, int sr, int sc, int M, char *S) {
if (W > 50 || H > 50) abort();
int y = sr-1, x = sc-1;
bad[x][y] = true;
rep(i, M) {
if (S[i] == 'N') y--;
if (S[i] == 'S') y++;
if (S[i] == 'W') x--;
if (S[i] == 'E') x++;
bad[x][y] = true;
}
}
int colour(int ar, int ac, int br, int bc) {
ar--, ac--, br--, bc--;
int V = 0;
for (int x=ac; x<=bc; x++) {
for (int y=ar; y<=br; y++) {
if (!bad[x][y]) id[x][y] = V++;
else id[x][y] = -1;
}
}
UF uf(V);
for (int x=ac; x<=bc; x++) {
for (int y=ar; y<=br; y++) {
if (x+1<=bc && !bad[x][y] && !bad[x+1][y]) uf.unite(id[x][y], id[x+1][y]);
if (y+1<=br && !bad[x][y] && !bad[x][y+1]) uf.unite(id[x][y], id[x][y+1]);
}
}
return uf.C;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
400 KB |
Output is correct |
3 |
Correct |
26 ms |
468 KB |
Output is correct |
4 |
Correct |
34 ms |
752 KB |
Output is correct |
5 |
Correct |
10 ms |
752 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
800 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
11 |
Correct |
28 ms |
876 KB |
Output is correct |
12 |
Correct |
19 ms |
924 KB |
Output is correct |
13 |
Correct |
14 ms |
1084 KB |
Output is correct |
14 |
Correct |
8 ms |
1084 KB |
Output is correct |
15 |
Correct |
2 ms |
1084 KB |
Output is correct |
16 |
Correct |
2 ms |
1084 KB |
Output is correct |
17 |
Correct |
2 ms |
1084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1084 KB |
Output is correct |
2 |
Correct |
2 ms |
1084 KB |
Output is correct |
3 |
Runtime error |
4 ms |
1416 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1084 KB |
Output is correct |
2 |
Runtime error |
5 ms |
1712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
400 KB |
Output is correct |
3 |
Correct |
26 ms |
468 KB |
Output is correct |
4 |
Correct |
34 ms |
752 KB |
Output is correct |
5 |
Correct |
10 ms |
752 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
800 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
11 |
Correct |
28 ms |
876 KB |
Output is correct |
12 |
Correct |
19 ms |
924 KB |
Output is correct |
13 |
Correct |
14 ms |
1084 KB |
Output is correct |
14 |
Correct |
8 ms |
1084 KB |
Output is correct |
15 |
Correct |
2 ms |
1084 KB |
Output is correct |
16 |
Correct |
2 ms |
1084 KB |
Output is correct |
17 |
Correct |
2 ms |
1084 KB |
Output is correct |
18 |
Runtime error |
4 ms |
1940 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
400 KB |
Output is correct |
3 |
Correct |
26 ms |
468 KB |
Output is correct |
4 |
Correct |
34 ms |
752 KB |
Output is correct |
5 |
Correct |
10 ms |
752 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
800 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
11 |
Correct |
28 ms |
876 KB |
Output is correct |
12 |
Correct |
19 ms |
924 KB |
Output is correct |
13 |
Correct |
14 ms |
1084 KB |
Output is correct |
14 |
Correct |
8 ms |
1084 KB |
Output is correct |
15 |
Correct |
2 ms |
1084 KB |
Output is correct |
16 |
Correct |
2 ms |
1084 KB |
Output is correct |
17 |
Correct |
2 ms |
1084 KB |
Output is correct |
18 |
Runtime error |
4 ms |
1940 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |