#include <bits/stdc++.h>
using namespace std;
char str[100001];
int r,c,sr,sc;
int l;
int arr[51][200001];
typedef pair<int,int> P;
vector<int> check[3];
void init(int rr,int cc,int srr,int scc,int m,char s[]) {
r=rr;
c=cc;
sr=srr;
sc=scc;
l=m;
for(int i=0;i<m;i++) {
str[i]=s[i];
}
arr[sr][sc]=1;
vector<P> v;
int x=sr;
int y=sc;
v.push_back(P(x,y));
for(int i=0;i<m;i++) {
if (str[i]=='W') {
y--;
}
if (str[i]=='E') {
y++;
}
if (str[i]=='N') {
x--;
}
if (str[i]=='S') {
x++;
}
arr[x][y]=1;
v.push_back(P(x,y));
}
}
struct UnionFind {
P p[51][51];
void init() {
for(int i=1;i<=r;i++) {
for(int j=1;j<=c;j++) {
p[i][j]=P(-1,-1);
}
}
}
P find(int x,int y) {
if (p[x][y]<P(0,0)) {
return P(x,y);
}
p[x][y]=find(p[x][y].first,p[x][y].second);
return p[x][y];
}
int merge(P a,P b) {
a=find(a.first,a.second);
b=find(b.first,b.second);
if (a==b) {
return 0;
}
p[b.first][b.second]=a;
return 1;
}
};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int solve1(int ar,int ac,int br,int bc) {
UnionFind uf;
uf.init();
int sum=0;
for(int i=ar;i<=br;i++) {
for(int j=ac;j<=bc;j++) {
if (arr[i][j]==0) {
sum++;
for(int k=0;k<4;k++) {
int x=i+dx[k];
int y=j+dy[k];
if (x>=ar&&x<=br&&y>=ac&&y<=bc&&arr[x][y]==0) {
sum-=uf.merge(P(i,j),P(x,y));
}
}
}
}
}
return sum;
}
int colour(int ar,int ac,int br,int bc) {
if (r<=50&&c<=50) {
return solve1(ar,ac,br,bc);
}
}
Compilation message
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:98:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
768 KB |
Output is correct |
3 |
Correct |
35 ms |
640 KB |
Output is correct |
4 |
Correct |
34 ms |
640 KB |
Output is correct |
5 |
Correct |
15 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
28 ms |
640 KB |
Output is correct |
12 |
Correct |
23 ms |
768 KB |
Output is correct |
13 |
Correct |
16 ms |
768 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
71 ms |
4364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Runtime error |
8 ms |
896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
768 KB |
Output is correct |
3 |
Correct |
35 ms |
640 KB |
Output is correct |
4 |
Correct |
34 ms |
640 KB |
Output is correct |
5 |
Correct |
15 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
28 ms |
640 KB |
Output is correct |
12 |
Correct |
23 ms |
768 KB |
Output is correct |
13 |
Correct |
16 ms |
768 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Runtime error |
7 ms |
1024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
768 KB |
Output is correct |
3 |
Correct |
35 ms |
640 KB |
Output is correct |
4 |
Correct |
34 ms |
640 KB |
Output is correct |
5 |
Correct |
15 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
28 ms |
640 KB |
Output is correct |
12 |
Correct |
23 ms |
768 KB |
Output is correct |
13 |
Correct |
16 ms |
768 KB |
Output is correct |
14 |
Correct |
11 ms |
768 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Runtime error |
7 ms |
1024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |