#include "rainbow.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int n,m;
set<pii> s;
vector<pii> ou,prr;
void init(int R, int C, int sr, int sc, int M, char *S) {
set<pii> pros;
--sr;
--sc;
for (int i=0;i<M;++i)
{
//if (s.find({sr,sc})!=s.end()) s.erase({sr,sc});
pros.insert({sr,sc});
for (int k=0;k<8;++k) s.insert({sr+dx[k],sc+dy[k]});
if (S[i]=='W') --sc;
if (S[i]=='E') ++sc;
if (S[i]=='N') --sr;
if (S[i]=='S') ++sr;
}
pros.insert({sr,sc});
for (auto a: pros) prr.pb(a);
for (int k=0;k<8;++k) s.insert({sr+dx[k],sc+dy[k]});
for (auto a: pros) if (s.find(a)!=s.end()) s.erase(a);
for (auto a: s) ou.pb(a);
//for (auto a: ou) cout<<a.x<<' '<<a.y<<endl;
}
int cnt,par[1000050];
bool pos[1000050];
vector<int> nap;
gp_hash_table<ll,int> nodes;
void add(int i)
{
nap.pb(i);
par[i]=i;
pos[i]=1;
++cnt;
}
int find(int i)
{
if (!pos[i]) return -1;
if (i==par[i]) return i;
return par[i]=find(par[i]);
}
void merge(int a,int b)
{
a=find(a);
b=find(b);
if (a==-1 || b==-1) return;
if (a==b) return;
par[a]=b;
--cnt;
}
void clear()
{
for (auto x: nap)
{
par[x]=-1;
pos[x]=0;
}
nap.clear();
cnt=0;
}
int colour(int ar, int ac, int br, int bc) {
int x1=ar-1,x2=br-1,y1=ac-1,y2=bc-1;
int cn=1;
nodes.clear();
for (auto a: ou) if (a.x>=x1 && a.x<=x2 && a.y>=y1 && a.y<=y2)
{
nodes[a.x*200000ll+a.y]=cn;
add(cn++);
for (int k=0;k<8;++k)
{
merge(nodes[(a.x+dx[k])*200000ll+(a.y+dy[k])],cn-1);
}
}
ll z=(y2-y1+1)*1ll*(x2-x1+1);
if (cnt==0)
{
for (auto a: prr) if (a.x>=x1 && a.x<=x2 && a.y>=y1 && a.y<=y2) --z;
if (z==0) return 0;
return 1;
}
int ans=cnt;
clear();
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
3006 ms |
23416 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
2452 ms |
42088 KB |
Output is correct |
3 |
Correct |
363 ms |
41900 KB |
Output is correct |
4 |
Correct |
381 ms |
61488 KB |
Output is correct |
5 |
Execution timed out |
3041 ms |
36976 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |