#include "rainbow.h"
#include <bits/stdc++.h>
#define ll int
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
const ll inf=1e18;
const ll mod=1e9+7;
const ll N=2e5+5;
const ld eps=1e-9;
bool vis[55][N];
bool f[55][N];
ll l=inf,r,u=inf,d;
ll xd[4]={-1,1,0,0},yd[4]={0,0,-1,1};
bool ok(ll x,ll y){
return !vis[x][y] && !f[x][y] && x>=u && x<=d && y>=l && y<=r;
}
void bfs(ll x,ll y){
ll i;
vis[x][y]=1;
for(i=0;i<4;i++){
ll nx=x+xd[i],ny=y+yd[i];
if(ok(nx,ny))bfs(nx,ny);
}
}
ll pref[4][N];
bool row;
void init(int r, int c, int sr, int sc, int m, char *s) {
ll i,j;
ll x=sr,y=sc;
f[x][y]=1;
for(i=0;i<m;i++){
if(s[i]=='N')x--;
if(s[i]=='S')x++;
if(s[i]=='W')y--;
if(s[i]=='E')y++;
f[x][y]=1;
chmin(u,x);
chmax(d,x);
chmin(l,y);
chmax(r,y);
}
if(r==2) {
row=1;
for(i=1;i<3;i++){
for(j=1;j<=r;j++){
pref[i][j]=pref[i][j-1];
if(f[i][j+1] && !f[i][j])pref[i][j]++;
}
}
}
}
int colour(int ar, int ac, int br, int bc) {
if(row){
if(u==d){
if(ac>=l && bc<=r && ar>=u && br<=d)return 0;
if(ac<=l && bc>=r && ar>=u && br<=d)return 2;
return 1;
}
ll c=0;
if(ar==br){
if(f[ar][bc+1] && !f[ar][bc])c=1;
return pref[ar][bc]-pref[ar][ac-1]+c;
}
if(f[ar][bc+1] && !f[ar][bc])c++;
if(f[br][bc+1] && !f[br][bc])c++;
if(ac<l)c--;
if(bc>r)c--;
return pref[0][bc]-pref[0][ac-1]+pref[1][bc]-pref[1][ac-1]+c;
}
u=ar,l=ac,d=br,r=bc;
ll c=0,i,j;
for(i=u;i<=d;i++){
for(j=l;j<=r;j++){
vis[i][j]=0;
}
}
for(i=u;i<=d;i++){
for(j=l;j<=r;j++){
if(vis[i][j] || f[i][j]) continue;
bfs(i,j);
c++;
}
}
return c;
}
Compilation message
rainbow.cpp:31:14: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
31 | const ll inf=1e18;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
6 ms |
18780 KB |
Output is correct |
3 |
Correct |
11 ms |
21084 KB |
Output is correct |
4 |
Correct |
10 ms |
21084 KB |
Output is correct |
5 |
Correct |
6 ms |
14940 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
11 ms |
19036 KB |
Output is correct |
12 |
Correct |
11 ms |
21060 KB |
Output is correct |
13 |
Correct |
7 ms |
19036 KB |
Output is correct |
14 |
Correct |
6 ms |
20828 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
6 ms |
18780 KB |
Output is correct |
3 |
Correct |
11 ms |
21084 KB |
Output is correct |
4 |
Correct |
10 ms |
21084 KB |
Output is correct |
5 |
Correct |
6 ms |
14940 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
11 ms |
19036 KB |
Output is correct |
12 |
Correct |
11 ms |
21060 KB |
Output is correct |
13 |
Correct |
7 ms |
19036 KB |
Output is correct |
14 |
Correct |
6 ms |
20828 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10588 KB |
Output is correct |
2 |
Correct |
6 ms |
18780 KB |
Output is correct |
3 |
Correct |
11 ms |
21084 KB |
Output is correct |
4 |
Correct |
10 ms |
21084 KB |
Output is correct |
5 |
Correct |
6 ms |
14940 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
11 ms |
19036 KB |
Output is correct |
12 |
Correct |
11 ms |
21060 KB |
Output is correct |
13 |
Correct |
7 ms |
19036 KB |
Output is correct |
14 |
Correct |
6 ms |
20828 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |