이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
const int maxn = 2e5 + 10;
bool mat[3][maxn];
int n, m, pi, pj, rios[3][maxn], prefix[3][maxn];
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R, m = C;
pi = sr, pj = sc;
mat[sr][sc] = 1;
for(int i=0;i<M;i++){
if(S[i] == 'N') --sr;
else if(S[i] == 'S') ++sr;
else if(S[i] == 'W') --sc;
else if(S[i] == 'E') ++sc;
mat[sr][sc] = 1;
}
for(int i=1;i<=2;i++){
for(int j=1;j<=m;j++){
rios[i][j] = rios[i][j-1];
if(mat[i][j]){
// rios[i][j++]++;
while(j <= m && mat[i][j]){
rios[i][j] = rios[i][j-1];
j++;
}
if(j <= m) rios[i][j] = rios[i][j-1] + 1;
}
}
}
for(int i=1;i<=2;i++)
for(int j=1;j<=m;j++)
prefix[i][j] = prefix[i][j-1] + (mat[i][j]);
for(int j=1;j<=m;j++)
prefix[0][j] = prefix[0][j-1] + (mat[1][j] && mat[2][j]);
for(int j=1;j<=m;j++){
rios[0][j] = rios[0][j-1];
if(mat[1][j] && mat[2][j]){
//rios[0][j++]++;
while(j <= m && mat[1][j] && mat[2][j]){
rios[0][j] = rios[0][j-1];
j++;
}
if(j <= m) rios[0][j] = rios[0][j-1] + 1;
}
}
// for(int i=0;i<=2;i++){
// cout << i << ": ";
// for(int j=1;j<=m;j++)
// cout << rios[i][j] << " \n"[j==m];
// }
// cout << "\n";
// for(int i=0;i<=2;i++){
// cout << i << ": ";
// for(int j=1;j<=m;j++)
// cout << prefix[i][j] << " \n"[j==m];
// }
}
int colour(int ar, int ac, int br, int bc) {
if(ar == br){
return (prefix[ar][bc] - prefix[ar][ac-1] == bc - ac + 1 ? 0 : rios[ar][bc] - rios[ar][ac] + 1);
}else{
return (prefix[0][bc] - prefix[0][ac-1] == bc - ac + 1 ? 0 : rios[0][bc] - rios[0][ac] + 1);
}
return 0;
}
# | 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... |