#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#define bug(x) cout << #x << " " << x << endl;
const int maxn = 2e5 + 10;
const int inf = 1e9;
int marc[4][maxn], sum[4][maxn], head[4][maxn];
int n, m, q;
int di[] = { 0, 1, 0, -1 };
int dj[] = { 1, 0, -1, 0 };
int linha1, linha2, coluna1, coluna2;
bool in_bounds( int i, int j ){
return linha1 <= i && i <= linha2 && coluna1 <= j && j <= coluna2;
}
void dfs( int i, int j ){
// bug(i);
// bug(j);
marc[i][j] = q;
for( int d = 0; d < 4; d++ ) if( marc[i + di[d]][j + dj[d]] < q && in_bounds( i + di[d], j + dj[d] ) ) dfs( i + di[d], j + dj[d] );
}
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R, m = C;
// bug(R);
coluna1 = 1, coluna2 = m;
marc[sr][sc] = inf;
for( int i = 0; i < M; i++ ){
char c = S[i];
if( c == 'N' ) sr--;
if( c == 'S' ) sr++;
if( c == 'W' ) sc--;
if( c == 'E' ) sc++;
marc[sr][sc] = inf;
}
for( int i = 1; i <= 2; i++ ){
// cout << "sla " << endl;
for( int j = m; j > 0; j-- ){
linha1 = linha2 = i;
if( !marc[i][j] ){
q = j;
dfs( i, j );
}
}
for( int j = 1;j <= m; j++ ){
sum[i][j] = sum[i][j - 1] + (( marc[i][j] == j ) ? 1 : 0 );
head[i][j] = marc[i][j];
if( marc[i][j] != inf ) marc[i][j] = 0;
// bug(sum[i][j]);
}
}
linha1 = 1; linha2 = 2;
for( int j = m; j > 0; j-- ) for( int i = 1;i <= 2; i++ ){
if( !marc[i][j] ){
q = j;
dfs( i, j );
}
}
for( int j = 1; j <= m; j++ ){
sum[3][j] = sum[3][j - 1] + (( marc[1][j] == j || marc[2][j] == j ) ? 1 : 0 );
head[3][j] = min( marc[1][j], marc[2][j] );
// bug(sum[3][j]);
}
}
int colour(int ar, int ac, int br, int bc) {
int id = (( ar < br ) ? 3 : ar );
int resp = sum[id][bc] - sum[id][ac - 1];
if( head[3][bc] > bc && head[3][bc] != inf ) resp++;
return resp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |