#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int LLI;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#include "rainbow.h"
int r,c;
vpii p;
int grid[2][200000];
vi num[200000];
vpii r1,r2,r12;
void init(int R,int C,int sr,int sc,int M,char *S) {
int i;
r = R,c = C;
sr--,sc--;
p.pb(mp(sr,sc));
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++;
p.pb(mp(sr,sc));
}
sort(p.begin(),p.end());
p.resize(unique(p.begin(),p.end())-p.begin());
if (R == 2) {
for (i = 0; i < p.size(); i++) grid[p[i].first][p[i].second] = 1;
int pre = -1;
for (i = 0; i < C; i++) {
if (grid[0][i]) {
if (pre != (i-1)) r1.pb(mp(pre+1,i-1));
pre = i;
}
}
if (pre != C-1) r1.pb(mp(pre+1,C-1));
pre = -1;
for (i = 0; i < C; i++) {
if (grid[1][i]) {
if (pre != (i-1)) r2.pb(mp(pre+1,i-1));
pre = i;
}
}
if (pre != C-1) r2.pb(mp(pre+1,C-1));
pre = -1;
for (i = 0; i < C; i++) {
if (grid[0][i] && grid[1][i]) {
if (pre != (i-1)) r12.pb(mp(pre+1,i-1));
pre = i;
}
}
if (pre != C-1) r12.pb(mp(pre+1,C-1));
}
else {
for (i = 0; i < p.size(); i++) num[p[i].first].pb(p[i].second);
}
}
struct seg { int y,l,r; };
int inter(seg a,seg b) {
return !((a.r < b.l) || (a.l > b.r));
}
seg segs[400000];
vi adjList[400000];
int visited[400000];
int doDFS(int u) {
if (visited[u]) return 0;
int i;
visited[u] = 1;
for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i]);
return 0;
}
int colour(int ar,int ac,int br,int bc) {
ar--,ac--,br--,bc--;
if (r == 2) {
vpii *_use;
if ((ar == 0) && (br == 0)) _use = &r1;
else if ((ar == 0) && (br == 1)) _use = &r12;
else _use = &r2;
vpii &use = *_use;
int l = lower_bound(use.begin(),use.end(),mp(ac,0))-use.begin()-1;
if ((l == -1) || (use[l].second < ac)) l++;
int r = upper_bound(use.begin(),use.end(),mp(bc,c))-use.begin()-1;
return r-l+1;
}
int i,j;
int t = 0;
for (i = ar; i <= br; i++) {
int pre = ac-1;
int pt = t;
for (j = 0; j < num[i].size(); j++) {
if (num[i][j] > bc) break;
if (num[i][j] >= ac) {
if (pre != num[i][j]-1) segs[t++] = (seg){i,pre+1,num[i][j]-1};
pre = num[i][j];
}
}
if (pre != bc) segs[t++] = (seg){i,pre+1,bc};
if (i > ar) {
int t2 = pt-1;
while ((t2 >= 0) && (segs[t2].y == i-1)) t2--;
t2++;
int k = t2;
for (j = pt; j < t; j++) {
while ((k < pt) && (segs[k].r < segs[j].l)) k++;
while ((k < pt) && inter(segs[k],segs[j])) {
adjList[k].pb(j);
adjList[j].pb(k);
k++;
}
if (k > t2) k--;
}
}
}
//for (i = 0; i <t;i++)cout<<segs[i].y<<","<<segs[i].l<<","<<segs[i].r<<endl;
int ans = 0;
fill(visited,visited+t,0);
for (i = 0; i < t; i++) {
if (!visited[i]) doDFS(i),ans++;
}
for (i = 0; i < t; i++) adjList[i].clear();
return ans;
}
Compilation message
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:31:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < p.size(); i++) grid[p[i].first][p[i].second] = 1;
~~^~~~~~~~~~
rainbow.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < p.size(); i++) num[p[i].first].pb(p[i].second);
~~^~~~~~~~~~
rainbow.cpp: In function 'int doDFS(int)':
rainbow.cpp:73:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i]);
~~^~~~~~~~~~~~~~~~~~~
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:95:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < num[i].size(); j++) {
~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
23 ms |
14640 KB |
Output is correct |
3 |
Correct |
18 ms |
14640 KB |
Output is correct |
4 |
Correct |
17 ms |
14640 KB |
Output is correct |
5 |
Correct |
19 ms |
14640 KB |
Output is correct |
6 |
Correct |
16 ms |
14764 KB |
Output is correct |
7 |
Correct |
17 ms |
14828 KB |
Output is correct |
8 |
Correct |
18 ms |
14828 KB |
Output is correct |
9 |
Correct |
17 ms |
14860 KB |
Output is correct |
10 |
Correct |
16 ms |
14864 KB |
Output is correct |
11 |
Correct |
18 ms |
15024 KB |
Output is correct |
12 |
Correct |
18 ms |
15024 KB |
Output is correct |
13 |
Correct |
26 ms |
15024 KB |
Output is correct |
14 |
Correct |
21 ms |
15108 KB |
Output is correct |
15 |
Correct |
18 ms |
15108 KB |
Output is correct |
16 |
Correct |
17 ms |
15108 KB |
Output is correct |
17 |
Correct |
17 ms |
15108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
15108 KB |
Output is correct |
2 |
Correct |
17 ms |
15108 KB |
Output is correct |
3 |
Correct |
110 ms |
16624 KB |
Output is correct |
4 |
Correct |
146 ms |
17432 KB |
Output is correct |
5 |
Correct |
106 ms |
17684 KB |
Output is correct |
6 |
Correct |
113 ms |
17684 KB |
Output is correct |
7 |
Correct |
118 ms |
17684 KB |
Output is correct |
8 |
Correct |
91 ms |
17684 KB |
Output is correct |
9 |
Correct |
104 ms |
17684 KB |
Output is correct |
10 |
Correct |
119 ms |
17684 KB |
Output is correct |
11 |
Correct |
138 ms |
17684 KB |
Output is correct |
12 |
Correct |
103 ms |
17684 KB |
Output is correct |
13 |
Correct |
99 ms |
17684 KB |
Output is correct |
14 |
Correct |
106 ms |
17684 KB |
Output is correct |
15 |
Correct |
122 ms |
17684 KB |
Output is correct |
16 |
Correct |
96 ms |
17684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
15108 KB |
Output is correct |
2 |
Correct |
41 ms |
23376 KB |
Output is correct |
3 |
Correct |
66 ms |
26216 KB |
Output is correct |
4 |
Correct |
58 ms |
26216 KB |
Output is correct |
5 |
Correct |
42 ms |
26216 KB |
Output is correct |
6 |
Correct |
56 ms |
29268 KB |
Output is correct |
7 |
Correct |
65 ms |
30920 KB |
Output is correct |
8 |
Correct |
24 ms |
30920 KB |
Output is correct |
9 |
Correct |
28 ms |
30920 KB |
Output is correct |
10 |
Correct |
23 ms |
30920 KB |
Output is correct |
11 |
Correct |
27 ms |
30920 KB |
Output is correct |
12 |
Correct |
26 ms |
30920 KB |
Output is correct |
13 |
Correct |
30 ms |
30920 KB |
Output is correct |
14 |
Correct |
33 ms |
30920 KB |
Output is correct |
15 |
Correct |
31 ms |
30920 KB |
Output is correct |
16 |
Correct |
53 ms |
30920 KB |
Output is correct |
17 |
Correct |
49 ms |
30920 KB |
Output is correct |
18 |
Correct |
58 ms |
30920 KB |
Output is correct |
19 |
Correct |
50 ms |
30920 KB |
Output is correct |
20 |
Correct |
45 ms |
30920 KB |
Output is correct |
21 |
Correct |
29 ms |
30920 KB |
Output is correct |
22 |
Correct |
30 ms |
30920 KB |
Output is correct |
23 |
Correct |
55 ms |
30920 KB |
Output is correct |
24 |
Correct |
64 ms |
30920 KB |
Output is correct |
25 |
Correct |
68 ms |
37060 KB |
Output is correct |
26 |
Correct |
83 ms |
46892 KB |
Output is correct |
27 |
Correct |
90 ms |
46892 KB |
Output is correct |
28 |
Correct |
96 ms |
46892 KB |
Output is correct |
29 |
Correct |
82 ms |
46892 KB |
Output is correct |
30 |
Correct |
74 ms |
46892 KB |
Output is correct |
31 |
Correct |
94 ms |
46892 KB |
Output is correct |
32 |
Correct |
86 ms |
46892 KB |
Output is correct |
33 |
Correct |
101 ms |
46892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
23 ms |
14640 KB |
Output is correct |
3 |
Correct |
18 ms |
14640 KB |
Output is correct |
4 |
Correct |
17 ms |
14640 KB |
Output is correct |
5 |
Correct |
19 ms |
14640 KB |
Output is correct |
6 |
Correct |
16 ms |
14764 KB |
Output is correct |
7 |
Correct |
17 ms |
14828 KB |
Output is correct |
8 |
Correct |
18 ms |
14828 KB |
Output is correct |
9 |
Correct |
17 ms |
14860 KB |
Output is correct |
10 |
Correct |
16 ms |
14864 KB |
Output is correct |
11 |
Correct |
18 ms |
15024 KB |
Output is correct |
12 |
Correct |
18 ms |
15024 KB |
Output is correct |
13 |
Correct |
26 ms |
15024 KB |
Output is correct |
14 |
Correct |
21 ms |
15108 KB |
Output is correct |
15 |
Correct |
18 ms |
15108 KB |
Output is correct |
16 |
Correct |
17 ms |
15108 KB |
Output is correct |
17 |
Correct |
17 ms |
15108 KB |
Output is correct |
18 |
Execution timed out |
3023 ms |
46892 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
23 ms |
14640 KB |
Output is correct |
3 |
Correct |
18 ms |
14640 KB |
Output is correct |
4 |
Correct |
17 ms |
14640 KB |
Output is correct |
5 |
Correct |
19 ms |
14640 KB |
Output is correct |
6 |
Correct |
16 ms |
14764 KB |
Output is correct |
7 |
Correct |
17 ms |
14828 KB |
Output is correct |
8 |
Correct |
18 ms |
14828 KB |
Output is correct |
9 |
Correct |
17 ms |
14860 KB |
Output is correct |
10 |
Correct |
16 ms |
14864 KB |
Output is correct |
11 |
Correct |
18 ms |
15024 KB |
Output is correct |
12 |
Correct |
18 ms |
15024 KB |
Output is correct |
13 |
Correct |
26 ms |
15024 KB |
Output is correct |
14 |
Correct |
21 ms |
15108 KB |
Output is correct |
15 |
Correct |
18 ms |
15108 KB |
Output is correct |
16 |
Correct |
17 ms |
15108 KB |
Output is correct |
17 |
Correct |
17 ms |
15108 KB |
Output is correct |
18 |
Execution timed out |
3023 ms |
46892 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |