#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int dydis = 2e5 + 100;
bool is[2][dydis] = {};
string mas;
int pref1[dydis], pref2[2][dydis];
void gen(int e, int s) {
is[e-1][s-1] = 1;
for(auto x : mas) {
if(x == 'N') e--;
if(x == 'S') e++;
if(x == 'W') s--;
if(x == 'E') s++;
is[e-1][s-1] = 1;
}
}
int kiek(int ind) {
int mas[2][2] = {{!is[0][ind-1], !is[0][ind]}, {!is[1][ind-1], !is[1][ind]}};
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);
/*cout << "mas:\n";
for(int i = 0; i < 2; i++) {
for(int j = 0; j < m; j++) {
cout << !is[i][j];
}
cout << endl;
}*/
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 < m; i++) {
pref1[i] = pref1[i-1];
pref1[i] += kiek(i);
// cout << "pref1[" << i << "] = " << pref1[i] << endl;
}
}
int colour(int ar, int ac, int br, int bc) {
ar--; ac--; br--; bc--;
if(ar == br) {
//cout << "pref[" << ac << "] = " << pref2[ar][ac] << ", pref[" << bc << "] = " << pref2[br][bc] << endl;
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:83:1: warning: control reaches end of non-void function [-Wreturn-type]
83 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
3 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 |
- |