#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1};
char dir[4] = {'N', 'E', 'S', 'W'};
bool ch[3][200009];
bool done[3][200009];
vector<int> s1, e1, s2, e2, s12, e12;
int n, m;
int r1, r2, c1, c2;
bool exist(int tr, int tc){
return tr>=r1 && tr<=r2 && tc>=c1 && tc<=c2;
}
void dfs(int r, int c){
done[r][c] = 1;
for(int k=0; k<4; k++){
int tr = r + dr[k];
int tc = c + dc[k];
if(exist(tr, tc) && !ch[tr][tc] && !done[tr][tc]){
dfs(tr, tc);
}
}
}
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R;
m = C;
ch[sr][sc] = 1;
for(int i=0; i<M; i++){
int k;
for(k=0; k<4; k++){
if(S[i] == dir[k])
break;
}
sr += dr[k];
sc += dc[k];
ch[sr][sc] = 1;
}
int i;
for(i=1; i<=n; i++){
if(!ch[1][i] && (i==1 || ch[1][i-1])){
s1.push_back(i);
}
if(!ch[2][i] && (i==1 || ch[2][i-1])){
s2.push_back(i);
}
if(!ch[1][i] && (i==n || ch[1][i+1])){
e1.push_back(i);
}
if(!ch[2][i] && (i==n || ch[2][i+1])){
e2.push_back(i);
}
if(!(ch[1][i] || ch[2][i]) && (i==1 || ch[1][i-1] || ch[2][i-1])){
s12.push_back(i);
}
if(!(ch[1][i] || ch[2][i]) && (i==n || ch[1][i+1] || ch[2][i+1])){
e12.push_back(i);
}
}
}
int colour(int ar, int ac, int br, int bc) {
int i, j;
if(ar==1 && br==1){
int idx1 = lower_bound(e1.begin(), e1.end(), ac) - e1.begin();
int idx2 = upper_bound(s1.begin(), s1.end(), bc) - s1.begin() - 1;
return idx2 - idx1 + 1;
}
if(ar==2 && br==2){
int idx1 = lower_bound(e2.begin(), e2.end(), ac) - e2.begin();
int idx2 = upper_bound(s2.begin(), s2.end(), bc) - s2.begin() - 1;
return idx2 - idx1 + 1;
}
if(ar==1 && br==2){
int idx1 = lower_bound(e12.begin(), e12.end(), ac) - e12.begin();
int idx2 = upper_bound(s12.begin(), s12.end(), bc) - s12.begin() - 1;
return idx2 - idx1 + 1;
}
}
Compilation message
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:61:6: warning: unused variable 'i' [-Wunused-variable]
61 | int i, j;
| ^
rainbow.cpp:61:9: warning: unused variable 'j' [-Wunused-variable]
61 | int i, j;
| ^
rainbow.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
79 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
448 KB |
Output is correct |
2 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |