#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 2e5+10;
pii dir[] = {{0,1},{1,0},{1,1}};
vector<pii> v;
set<pii> st;
void init(int R, int C, int sr, int sc, int M, char *S) {
st.clear();
v.clear();
pii now = pii(sr,sc);
v.push_back(now);
for(int i = 0;i<M;i++){
if(S[i] == 'N')now.fs--;
else if(S[i] == 'S')now.fs++;
else if(S[i] == 'E')now.sc++;
else if(S[i] == 'W')now.sc--;
v.push_back(now);
}
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
}
int colour(int ar, int ac, int br, int bc) {
st.clear();
vector<pii> vv;
bool con = false;
for(auto &i:v){
if(i.fs<ar||i.fs>br||i.sc<ac||i.sc>bc)continue;
if(i.fs == ar||i.fs == br||i.sc == ac||i.sc == bc)con = true;
vv.push_back(i);
}
if(vv.empty())con = true;
for(int i = ar-1;i<=br+1;i++){
vv.push_back(pii(i,ac-1));
vv.push_back(pii(i,bc+1));
}
for(int i = ac-1;i<=bc+1;i++){
vv.push_back(pii(ar-1,i));
vv.push_back(pii(br+1,i));
}
swap(v,vv);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
//for(auto &i:v)cerr<<i.fs<<','<<i.sc<<' ';cerr<<endl;
for(auto &i:v)st.insert(i);
int ecnt = 0,vcnt = 0;
vcnt = v.size();
for(auto &i:v){
if(st.find(pii(i.fs+1,i.sc)) != st.end())ecnt++;
if(st.find(pii(i.fs,i.sc+1)) != st.end())ecnt++;
}
for(auto &i:v){
if(st.find(pii(i.fs+1,i.sc+1)) != st.end()){
if(st.find(pii(i.fs+1,i.sc)) == st.end()&&st.find(pii(i.fs,i.sc+1)) == st.end())ecnt++;
}
if(st.find(pii(i.fs+1,i.sc-1)) != st.end()){
if(st.find(pii(i.fs+1,i.sc)) == st.end()&&st.find(pii(i.fs,i.sc-1)) == st.end())ecnt++;
}
}
int ans = 2+ecnt-vcnt;
//cerr<<vcnt<<' '<<ecnt<<endl;
for(auto &i:v){
int c = 0;
for(auto &d:dir){
if(st.find(pii(i.fs+d.fs,i.sc+d.sc)) != st.end())c++;
}
if(c == 3)ans--;
}
swap(v,vv);
return ans-con;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
80 ms |
344 KB |
Output is correct |
3 |
Correct |
52 ms |
732 KB |
Output is correct |
4 |
Correct |
61 ms |
344 KB |
Output is correct |
5 |
Correct |
115 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
93 ms |
504 KB |
Output is correct |
12 |
Correct |
168 ms |
348 KB |
Output is correct |
13 |
Correct |
193 ms |
344 KB |
Output is correct |
14 |
Correct |
345 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
3056 ms |
24676 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
272 ms |
20516 KB |
Output is correct |
3 |
Correct |
285 ms |
20804 KB |
Output is correct |
4 |
Correct |
254 ms |
19060 KB |
Output is correct |
5 |
Correct |
134 ms |
9788 KB |
Output is correct |
6 |
Correct |
424 ms |
28188 KB |
Output is correct |
7 |
Correct |
638 ms |
40760 KB |
Output is correct |
8 |
Correct |
31 ms |
3276 KB |
Output is correct |
9 |
Correct |
19 ms |
2256 KB |
Output is correct |
10 |
Correct |
9 ms |
1236 KB |
Output is correct |
11 |
Correct |
32 ms |
3536 KB |
Output is correct |
12 |
Correct |
73 ms |
7252 KB |
Output is correct |
13 |
Correct |
73 ms |
7252 KB |
Output is correct |
14 |
Correct |
74 ms |
7400 KB |
Output is correct |
15 |
Correct |
73 ms |
7240 KB |
Output is correct |
16 |
Correct |
345 ms |
23364 KB |
Output is correct |
17 |
Correct |
303 ms |
22080 KB |
Output is correct |
18 |
Correct |
411 ms |
28432 KB |
Output is correct |
19 |
Correct |
404 ms |
28420 KB |
Output is correct |
20 |
Correct |
376 ms |
23872 KB |
Output is correct |
21 |
Correct |
163 ms |
10724 KB |
Output is correct |
22 |
Correct |
133 ms |
9024 KB |
Output is correct |
23 |
Correct |
191 ms |
13288 KB |
Output is correct |
24 |
Correct |
254 ms |
19012 KB |
Output is correct |
25 |
Correct |
791 ms |
51796 KB |
Output is correct |
26 |
Correct |
807 ms |
51512 KB |
Output is correct |
27 |
Correct |
807 ms |
50480 KB |
Output is correct |
28 |
Correct |
859 ms |
49404 KB |
Output is correct |
29 |
Correct |
820 ms |
47044 KB |
Output is correct |
30 |
Correct |
752 ms |
49312 KB |
Output is correct |
31 |
Correct |
800 ms |
50584 KB |
Output is correct |
32 |
Correct |
800 ms |
50740 KB |
Output is correct |
33 |
Correct |
845 ms |
50672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
80 ms |
344 KB |
Output is correct |
3 |
Correct |
52 ms |
732 KB |
Output is correct |
4 |
Correct |
61 ms |
344 KB |
Output is correct |
5 |
Correct |
115 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
93 ms |
504 KB |
Output is correct |
12 |
Correct |
168 ms |
348 KB |
Output is correct |
13 |
Correct |
193 ms |
344 KB |
Output is correct |
14 |
Correct |
345 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
3016 ms |
3740 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
80 ms |
344 KB |
Output is correct |
3 |
Correct |
52 ms |
732 KB |
Output is correct |
4 |
Correct |
61 ms |
344 KB |
Output is correct |
5 |
Correct |
115 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
93 ms |
504 KB |
Output is correct |
12 |
Correct |
168 ms |
348 KB |
Output is correct |
13 |
Correct |
193 ms |
344 KB |
Output is correct |
14 |
Correct |
345 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
3016 ms |
3740 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |