#include <bits/stdc++.h>
#include "rainbow.h"
//#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=100;
int g[N][N],vis[N][N];
int r,c;
void init(int R, int C, int sr, int sc, int M, char *S){
r=R;
c=C;
g[sr][sc]=1;
for(int i=0;i<M;i++){
if(S[i]=='N')sr--;
else if(S[i]=='S')sr++;
else if(S[i]=='W')sc--;
else sc++;
g[sr][sc]=1;
}
}
int colour(int ar, int ac, int br, int bc){
queue <pair <int,int> > q;
vector <int> X={0,0,-1,1};
vector <int> Y={1,-1,0,0};
int ans=0;
for(int i=ar;i<=br;i++){
for(int j=ac;j<=bc;j++){
if(!vis[i][j] && !g[i][j]){
ans++;
vis[i][j]=1;
q.push({i,j});
while(!q.empty()){
int x=q.front().ff;
int y=q.front().ss;
q.pop();
for(int k=0;k<4;k++){
if(x+X[k]>=ar && x+X[k]<=br && y+Y[k]>=ac && y+Y[k]<=bc && !g[x+X[k]][y+Y[k]] && !vis[x+X[k]][y+Y[k]]){
vis[x+X[k]][y+Y[k]]=1;
q.push({x+X[k],y+Y[k]});
}
}
}
}
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
vis[i][j]=0;
}
}
return ans;
}
/*signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int r,c,m,q,x,y;
cin>>r>>c>>m>>q>>x>>y;
string s;
cin>>s;
init(r,c,x,y,m,s);
for(int i=0;i<q;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<colour(a,b,c,d)<<"\n";
}
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
15 ms |
348 KB |
Output is correct |
4 |
Correct |
14 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
12 ms |
496 KB |
Output is correct |
12 |
Correct |
10 ms |
496 KB |
Output is correct |
13 |
Correct |
8 ms |
348 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
15 ms |
348 KB |
Output is correct |
4 |
Correct |
14 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
12 ms |
496 KB |
Output is correct |
12 |
Correct |
10 ms |
496 KB |
Output is correct |
13 |
Correct |
8 ms |
348 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
15 ms |
348 KB |
Output is correct |
4 |
Correct |
14 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
12 ms |
496 KB |
Output is correct |
12 |
Correct |
10 ms |
496 KB |
Output is correct |
13 |
Correct |
8 ms |
348 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |