#include "rainbow.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
const int N=2e5+5;
int n,m,t,q;
int used[1005][1005];
vector< vector< int> > a;
void dfs(int x, int y, int x1, int x2, int y1, int y2){
if(used[x][y]) return;
if(x<x1 || x>x2 || y<y1 || y>y2 || a[x][y]) return;
used[x][y]=1;
dfs(x-1,y,x1,x2,y1,y2);
dfs(x+1,y,x1,x2,y1,y2);
dfs(x,y-1,x1,x2,y1,y2);
dfs(x,y+1,x1,x2,y1,y2);
}
int pref[N],pr[N][2];
void init(int R, int C, int sr, int sc, int M, char *S) {
n=R,m=C;
int x=sr,y=sc;
t=M;
a.resize(n+2,vector<int>(m+2));
a[x][y]=1;
for(int i=0;i<t;i++){
char c=S[i];
if(c=='N') x--;
else if(c=='S') x++;
else if(c=='E') y++;
else y--;
a[x][y]=1;
}
a[1][0]=a[2][0]=1;
for(int i=1;i<=m;i++){
pr[i][0]+=pr[i-1][0];
pr[i][1]+=pr[i-1][1];
pref[i]+=pref[i-1];
if(a[1][i] && a[2][i]) continue;
if(a[1][i-1] && a[2][i-1]) pref[i]++;
if(a[1][i-1] && !a[1][i]) pr[i][0]++;
if(a[2][i-1] && !a[2][i]) pr[i][1]++;
}
}
int colour(int ar, int ac, int br, int bc) {
if(n==2){
if(ar==br){
if(ar==1) return pr[bc][0]-max(pr[ac][0]-1,0);
else return pr[bc][1]-max(pr[ac][1]-1,0);
}
else{
return pref[bc]-max(pref[ac]-1,0);
}
}
else{
int x1=ar,x2=br,y1=ac,y2=bc;
for(int i=x1;i<=x2;i++)
for(int j=y1;j<=y2;j++) used[i][j]=0;
int ans=0;
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
if(!used[i][j] && !a[i][j]){
ans++;
dfs(i,j,x1,x2,y1,y2);
}
}
}
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
7 ms |
4444 KB |
Output is correct |
3 |
Correct |
14 ms |
4700 KB |
Output is correct |
4 |
Correct |
14 ms |
4700 KB |
Output is correct |
5 |
Correct |
7 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
11 ms |
4700 KB |
Output is correct |
12 |
Correct |
9 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4696 KB |
Output is correct |
14 |
Correct |
5 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Runtime error |
376 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
7 ms |
4444 KB |
Output is correct |
3 |
Correct |
14 ms |
4700 KB |
Output is correct |
4 |
Correct |
14 ms |
4700 KB |
Output is correct |
5 |
Correct |
7 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
11 ms |
4700 KB |
Output is correct |
12 |
Correct |
9 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4696 KB |
Output is correct |
14 |
Correct |
5 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
7 ms |
4444 KB |
Output is correct |
3 |
Correct |
14 ms |
4700 KB |
Output is correct |
4 |
Correct |
14 ms |
4700 KB |
Output is correct |
5 |
Correct |
7 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
11 ms |
4700 KB |
Output is correct |
12 |
Correct |
9 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4696 KB |
Output is correct |
14 |
Correct |
5 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |