#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define F first
#define S second
const int maxN = 2e5 + 10;
int n, m;
int cnt[3][maxN];
bool mark[3][maxN];
void init(int R, int C, int sr, int sc, int M, char *T) {
n = R;
m = C;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
mark[i][j] = 1;
pii cur = {sr, sc};
mark[cur.F][cur.S] = false;
for(int i = 0; i < M; i++) {
char c = T[i];
if(c == 'N') cur.F--;
if(c == 'S') cur.F++;
if(c == 'W') cur.S--;
if(c == 'E') cur.S++;
mark[cur.F][cur.S] = false;
}
mark[1][0] = false;
mark[2][0] = false;
for(int i = 1; i <= m; i++) {
cnt[0][i] = cnt[0][i-1] + (mark[1][i-1] == 0 and mark[1][i] == 1);
cnt[1][i] = cnt[1][i-1] + (mark[2][i-1] == 0 and mark[2][i] == 1);
cnt[2][i] = cnt[2][i-1] + ((mark[1][i]|mark[2][i])&(!(mark[1][i]&mark[1][i-1]))&(!(mark[2][i]&mark[2][i-1])));
}
}
int colour(int ar, int ac, int br, int bc) {
if(ar == br) {
if(ar == 1)
return cnt[0][bc] - cnt[0][ac-1] + (mark[1][ac]&mark[1][ac-1]);
return cnt[1][bc] - cnt[1][ac-1] + (mark[2][ac]&mark[2][ac-1]);
}
return cnt[2][bc] - cnt[2][ac-1] + ((mark[1][ac]&mark[1][ac-1])|(mark[2][ac]&mark[2][ac-1]));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |