#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int dydis = 2e5;
bool is[2][dydis] = {};
string mas;
int pref1[dydis], pref2[2][dydis];
void gen(int e, int s) {
is[e][s] = 1;
for(auto x : mas) {
if(x == 'N') e--;
if(x == 'S') e++;
if(x == 'W') s--;
if(x == 'E') s++;
is[e][s] = 1;
}
}
int kiek(int ind) {
int mas[2][2] = {{!is[ind-1][0], !is[ind-1][1]}, {!is[ind][0], !is[ind][1]}};
if(mas[0][1] == mas[1][1]) {
if(!mas[0][1]) return 0;
if(mas[0][0] || mas[1][0]) return 0;
return 1;
}
if(mas[1][1]) {
swap(mas[0][0], mas[1][0]);
swap(mas[0][1], mas[1][1]);
}
if(mas[0][0]) return 0;
if(!mas[0][0]) return 1;
}
void init(int R, int C, int sr, int sc, int M, char *S) {
n = R; m = C;
for(int i = 0; i < M; i++) mas.push_back(S[i]);
gen(sr, sc);
for(int i = 0; i < 2; i++){
pref2[i][0] = (!is[i][0]);
for(int j = 1; j < m; j++) {
pref2[i][j] = pref2[i][j-1];
if(is[i][j] == is[i][j-1]) continue;
if(!is[i][j]) pref2[i][j]++;
}
}
pref1[0] = (!is[0][0] || !is[1][0]);
for(int i = 1; i < n; i++) {
pref1[i] = pref1[i-1];
pref1[i] += kiek(i);
}
}
int colour(int ar, int ac, int br, int bc) {
if(ar == br) {
if(!is[ar][ac] && !is[br][bc]) {
return pref2[br][bc] - pref2[ar][ac] + 1;
}
if(is[ar][ac] && is[br][bc]) {
return pref2[br][bc] - pref2[ar][ac];
}
if(is[ar][ac] && !is[br][bc]) {
return pref2[br][bc] - pref2[ar][ac];
}
if(!is[ar][ac] && is[br][bc]) {
return pref2[br][bc] - pref2[ar][ac] + 1;
}
}else {
return pref1[bc] - pref1[ac] + (!is[0][ac] || !is[1][ac] || !is[0][bc] || !is[1][bc]);
}
// return ret;
}
Compilation message
rainbow.cpp: In function 'int kiek(int)':
rainbow.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
34 | }
| ^
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
74 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1108 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |