#include <bits/stdc++.h>
#ifndef SKY
#include "rainbow.h"
#endif // SKY
using namespace std;
#define N 200010
#define ll long long
#define fs first
#define sc second
#define ii pair<ll,int>
#define pb push_back
int r,c,m;
struct BIT
{
unordered_map<int,int>bit[N];
void update(int x,int y,int val)
{
x=r-x+1;
y=c-y+1;
for(int u=x;u>0;u-=u&(-u))
for(int v=y;v>0;v-=v&(-v))
bit[u][v]+=val;
}
int get(int x,int y)
{
x=r-x+1;
y=c-y+1;
int res=0;
for(int u=x;u<=r;u+=u&(-u))
for(int v=y;v<=c;v+=v&(-v))
if(bit[u].find(v)!=bit[u].end())
res+=bit[u][v];
return res;
}
};
int top,bot,lef,righ,ktr[110][110],visited[110][110],times;
vector<int>row={0,0,-1,1},col={-1,1,0,0};
void init(int RRR, int CCC, int sr, int sc, int MMM, char *S)
{
r=RRR;
c=CCC;
m=MMM;
ktr[sr][sc]=1;
for(int i=1;i<=m;i++)
{
char ch=*S;
if(i!=m)
S++;
if(ch=='N')
sr--;
if(ch=='S')
sr++;
if(ch=='E')
sc++;
if(ch=='W')
sc--;
ktr[sr][sc]=1;
//cout<<sr<<" "<<sc<<endl;
}
}
bool check(int u,int v)
{
return(u>=top&&u<=bot&&v>=lef&&v<=righ&&ktr[u][v]==0&&visited[u][v]!=times);
}
void DFS(int u,int v)
{
visited[u][v]=times;
for(int i=0;i<4;i++)
if(check(u+row[i],v+col[i]))
DFS(u+row[i],v+col[i]);
}
int colour(int ar, int ac, int br, int bc)
{
top=ar;
bot=br;
lef=ac;
righ=bc;
times++;
int res=0;
//cout<<ar<<" "<<ac<<" "<<br<<" "<<bc<<endl;
for(int i=top;i<=bot;i++)
for(int j=lef;j<=righ;j++)
if(ktr[i][j]==0&&visited[i][j]!=times)
{
// cout<<i<<" "<<j<<endl;
res++;
DFS(i,j);
}
return res;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int r,c,sr,sc,m;
string S;
cin>>r>>c>>sr>>sc>>m>>S;
init(r,c,sr,sc,m,&S[0]);
int q;
cin>>q;
while(q--)
{
int ar,ac,br,bc;
cin>>ar>>ac>>br>>bc;
cout<<colour(ar,ac,br,bc)<<endl;
}
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
316 KB |
Output is correct |
3 |
Correct |
17 ms |
528 KB |
Output is correct |
4 |
Correct |
16 ms |
448 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
13 ms |
448 KB |
Output is correct |
12 |
Correct |
10 ms |
468 KB |
Output is correct |
13 |
Correct |
8 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Runtime error |
2 ms |
852 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
316 KB |
Output is correct |
3 |
Correct |
17 ms |
528 KB |
Output is correct |
4 |
Correct |
16 ms |
448 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
13 ms |
448 KB |
Output is correct |
12 |
Correct |
10 ms |
468 KB |
Output is correct |
13 |
Correct |
8 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Runtime error |
2 ms |
836 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
316 KB |
Output is correct |
3 |
Correct |
17 ms |
528 KB |
Output is correct |
4 |
Correct |
16 ms |
448 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
13 ms |
448 KB |
Output is correct |
12 |
Correct |
10 ms |
468 KB |
Output is correct |
13 |
Correct |
8 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Runtime error |
2 ms |
836 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |