#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 *S) {
n = R;
m = C;
pii cur = {sr, sc};
mark[cur.F][cur.S] = true;
for(int i = 0; i < M; i++) {
char c = S[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] = true;
}
mark[1][0] = true;
mark[2][0] = true;
for(int i = 1; i <= m; i++) {
cnt[0][i] = cnt[0][i-1] + (mark[1][i-1] == 1 and mark[1][i] == 0);
cnt[1][i] = cnt[1][i-1] + (mark[2][i-1] == 1 and mark[2][i] == 0);
cnt[2][i] = cnt[2][i-1] + ((mark[1][i-1]&mark[1][i])|(mark[2][i-1]&mark[2][i]) == 0);
}
}
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-1])&(!mark[1][ac]))|((!mark[2][ac-1])&(!mark[2][ac])));
}
# | 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... |