/****************************D A N E T****************************
*** ██████╗ █████╗ ███╗ ██╗ ███████╗ ████████╗ ***
*** ██╔══██╗ ██╔══██╗ ████╗ ██║ ██╔════╝ ╚══██╔══╝ ***
*** ██║ ██║ ███████║ ██╔██╗ ██║ █████╗ ██║ ***
*** ██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══╝ ██║ ***
*** ██████╔╝ ██║ ██║ ██║ ╚████║ ███████╗ ██║ ***
*** ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚══════╝ ***
****************************D A N E T****************************/
#include <bits/stdc++.h>
using namespace std;
/**************************P R A G M As**************************/
#pragma GCC optimize("O3")
/**************************D E F I N Es**************************/
#define Tof_Io ios_base::sync_with_stdio(false);cin.tie(0) , cout.tie(0);
//#define int long long int
#define double long double
#define pb push_back
#define endl '\n'
/*****************D E F I N Es-F U N C T I O Nes*****************/
#define debug(x) cerr << #x << ": " << x << endl
#define kill(x) cout << x << endl, exit(0)
#define all(x) x.begin(),x.end()
#define yes cout << "Yes"
#define no cout <<"No"
/***************************C O N S Ty***************************/
const double PI = 3.141592653589793;
const int mod = 998244353;//1e9+7 998244353
const int inf = 1e9+9;
const int logt = 18;
const int N = 500 + 23;
/***************************B U I L Dy***************************/
int fac[N];
int inv[N];
vector<int> adj[N];
bool seen[N][N];
string str;
int n, m;
vector<pair<int, int> > dx = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
/****************************N O T Ey****************************/
/*
*/
/***********************F U N C T I O N es***********************/
int dnt_pow (int a, int b, int md = mod){int ans = 1; while(b){if(b&1){ans = (a*ans)%md;}a = (a*a)%md;b >>= 1;}return ans ;}
void dnt_bld (){fac[0] = 1; inv[0] = dnt_pow(fac[0],mod-2) ;for(int i = 1 ; i < N ; i++) {fac[i] = (fac[i-1] * i) % mod;inv[i] = dnt_pow( fac[i] , mod-2);}}
int dnt_ncr (int n,int r){return fac[n] * inv[r] % mod * inv[n-r] % mod;}
void dnt_cal(int e, int s) {seen[e][s] = 1;for(auto x : str) {if(x == 'N') e--;if(x == 'S') e++;if(x == 'W') s--;if(x == 'E') s++;seen[e][s] = 1;}}
/****************************************************************/
void init(int R, int C, int sr, int sc, int M, char *S)
{
n = R;
m = C;
for(int i = 0; i < M; i++) str.push_back(S[i]);
dnt_cal(sr, sc);
}
int colour(int ar, int ac, int br, int bc)
{
int ans = 0;
bool seen2[N][N] = {};
for(int i = ar; i <= br; i++)
{
for(int j = ac; j <= bc; j++)
{
if(seen2[i][j]) continue ;
if(seen[i][j]) continue;
int e = i;
int s = j;
int pe, ps;
//BFS:
queue<pair<int, int> > q;
q.push(make_pair(e,s));
while(!q.empty())
{
e = q.front().first;
s = q.front().second;
q.pop();
for(auto x : dx)
{
pe = x.first + e;
ps = x.second + s;
if(pe < ar or pe > br or ps < ac or ps > bc)
{
continue;
}
if(seen2[pe][ps])
{
continue;
}
if(seen[pe][ps])
{
continue;
}
seen2[pe][ps] = 1;
q.push(make_pair(pe,ps));
}
}
ans++;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
8 ms |
604 KB |
Output is correct |
3 |
Correct |
15 ms |
604 KB |
Output is correct |
4 |
Correct |
15 ms |
760 KB |
Output is correct |
5 |
Correct |
10 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
14 ms |
756 KB |
Output is correct |
12 |
Correct |
12 ms |
604 KB |
Output is correct |
13 |
Correct |
10 ms |
604 KB |
Output is correct |
14 |
Correct |
12 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Execution timed out |
3043 ms |
1200 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Runtime error |
1 ms |
1116 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
8 ms |
604 KB |
Output is correct |
3 |
Correct |
15 ms |
604 KB |
Output is correct |
4 |
Correct |
15 ms |
760 KB |
Output is correct |
5 |
Correct |
10 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
14 ms |
756 KB |
Output is correct |
12 |
Correct |
12 ms |
604 KB |
Output is correct |
13 |
Correct |
10 ms |
604 KB |
Output is correct |
14 |
Correct |
12 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Runtime error |
1 ms |
1372 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
8 ms |
604 KB |
Output is correct |
3 |
Correct |
15 ms |
604 KB |
Output is correct |
4 |
Correct |
15 ms |
760 KB |
Output is correct |
5 |
Correct |
10 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
14 ms |
756 KB |
Output is correct |
12 |
Correct |
12 ms |
604 KB |
Output is correct |
13 |
Correct |
10 ms |
604 KB |
Output is correct |
14 |
Correct |
12 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Runtime error |
1 ms |
1372 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |