#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "rainbow.h"
int r,c;
int lx,rx,ly,ry;
int **pre1,**pre2,**pre3,**pre4;
void init(int R,int C,int sr,int sc,int M,char *S) {
int i,j;
r = R,c = C;
pre1 = new int*[R+1];
pre2 = new int*[R+1];
pre3 = new int*[R+1];
pre4 = new int*[R+1];
for (i = 0; i <= R; i++) {
pre1[i] = new int[C+1];
pre2[i] = new int[C+1];
pre3[i] = new int[C+1];
pre4[i] = new int[C+1];
for (j = 0; j <= C; j++) pre1[i][j] = pre2[i][j] = pre3[i][j] = pre4[i][j] = 0;
}
for (i = 1; i <= R; i++) {
for (j = 1; j <= C; j++) pre1[i][j] = pre2[i][j] = pre3[i][j] = pre4[i][j] = 1;
}
sr--,sc--;
lx = rx = sc,ly = ry = sr;
pre1[sr+1][sc+1] = 0;
pre2[sr+1][sc+1] = pre2[sr][sc+1] = 0;
pre3[sr+1][sc+1] = pre3[sr+1][sc] = 0;
pre4[sr+1][sc+1] = pre4[sr][sc+1] = pre4[sr+1][sc] = pre4[sr][sc] = 0;
for (i = 0; i < M; i++) {
if (S[i] == 'N') sr--;
else if (S[i] == 'S') sr++;
else if (S[i] == 'W') sc--;
else sc++;
lx = min(lx,sc),rx = max(rx,sc);
ly = min(lx,sr),ry = max(ry,sr);
pre1[sr+1][sc+1] = 0;
pre2[sr+1][sc+1] = pre2[sr][sc+1] = 0;
pre3[sr+1][sc+1] = pre3[sr+1][sc] = 0;
pre4[sr+1][sc+1] = pre4[sr][sc+1] = pre4[sr+1][sc] = pre4[sr][sc] = 0;
}
for (i = 1; i <= R; i++) {
for (j = 1; j <= C; j++) {
pre1[i][j] += pre1[i-1][j]+pre1[i][j-1]-pre1[i-1][j-1];
pre2[i][j] += pre2[i-1][j]+pre2[i][j-1]-pre2[i-1][j-1];
pre3[i][j] += pre3[i-1][j]+pre3[i][j-1]-pre3[i-1][j-1];
pre4[i][j] += pre4[i-1][j]+pre4[i][j-1]-pre4[i-1][j-1];
}
}
}
int colour(int ar,int ac,int br,int bc) {
ar--,ac--,br--,bc--;
int ans = 0;
ans += pre1[br+1][bc+1]-pre1[ar][bc+1]-pre1[br+1][ac]+pre1[ar][ac];
ans -= pre2[br][bc+1]-pre2[ar][bc+1]-pre2[br][ac]+pre2[ar][ac];
ans -= pre3[br+1][bc]-pre3[ar][bc]-pre3[br+1][ac]+pre3[ar][ac];
ans += pre4[br][bc]-pre4[ar][bc]-pre4[br][ac]+pre4[ar][ac];
if ((ar < ly) && (br > ry) && (ac < lx) && (bc > rx)) ans++;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
4 ms |
576 KB |
Output is correct |
5 |
Correct |
4 ms |
576 KB |
Output is correct |
6 |
Correct |
3 ms |
588 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
732 KB |
Output is correct |
9 |
Correct |
4 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
4 ms |
732 KB |
Output is correct |
12 |
Correct |
4 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
792 KB |
Output is correct |
14 |
Correct |
3 ms |
968 KB |
Output is correct |
15 |
Correct |
3 ms |
968 KB |
Output is correct |
16 |
Correct |
3 ms |
968 KB |
Output is correct |
17 |
Correct |
2 ms |
968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
968 KB |
Output is correct |
2 |
Correct |
2 ms |
968 KB |
Output is correct |
3 |
Correct |
122 ms |
13560 KB |
Output is correct |
4 |
Correct |
114 ms |
16460 KB |
Output is correct |
5 |
Correct |
130 ms |
19312 KB |
Output is correct |
6 |
Correct |
109 ms |
19320 KB |
Output is correct |
7 |
Correct |
113 ms |
19340 KB |
Output is correct |
8 |
Correct |
178 ms |
19420 KB |
Output is correct |
9 |
Correct |
126 ms |
19420 KB |
Output is correct |
10 |
Correct |
190 ms |
19420 KB |
Output is correct |
11 |
Correct |
145 ms |
19420 KB |
Output is correct |
12 |
Correct |
89 ms |
19420 KB |
Output is correct |
13 |
Correct |
101 ms |
19444 KB |
Output is correct |
14 |
Correct |
101 ms |
19444 KB |
Output is correct |
15 |
Correct |
145 ms |
19444 KB |
Output is correct |
16 |
Correct |
106 ms |
19444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
968 KB |
Output is correct |
2 |
Runtime error |
1910 ms |
1049600 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
4 ms |
576 KB |
Output is correct |
5 |
Correct |
4 ms |
576 KB |
Output is correct |
6 |
Correct |
3 ms |
588 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
732 KB |
Output is correct |
9 |
Correct |
4 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
4 ms |
732 KB |
Output is correct |
12 |
Correct |
4 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
792 KB |
Output is correct |
14 |
Correct |
3 ms |
968 KB |
Output is correct |
15 |
Correct |
3 ms |
968 KB |
Output is correct |
16 |
Correct |
3 ms |
968 KB |
Output is correct |
17 |
Correct |
2 ms |
968 KB |
Output is correct |
18 |
Runtime error |
187 ms |
1049600 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Correct |
4 ms |
576 KB |
Output is correct |
5 |
Correct |
4 ms |
576 KB |
Output is correct |
6 |
Correct |
3 ms |
588 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
2 ms |
732 KB |
Output is correct |
9 |
Correct |
4 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
732 KB |
Output is correct |
11 |
Correct |
4 ms |
732 KB |
Output is correct |
12 |
Correct |
4 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
792 KB |
Output is correct |
14 |
Correct |
3 ms |
968 KB |
Output is correct |
15 |
Correct |
3 ms |
968 KB |
Output is correct |
16 |
Correct |
3 ms |
968 KB |
Output is correct |
17 |
Correct |
2 ms |
968 KB |
Output is correct |
18 |
Runtime error |
187 ms |
1049600 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
19 |
Halted |
0 ms |
0 KB |
- |