This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool is[501][501] = {};
string mas;
void gen(int e, int s) {
for(auto x : mas) {
is[e][s] = 1;
if(x == 'N') e--;
if(x == 'S') e++;
if(x == 'W') s--;
if(x == 'E') s++;
is[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++) mas.push_back(S[i]);
gen(sr, sc);
}
int colour(int ar, int ac, int br, int bc) {
int ret = 0;
bool vis[501][501] = {};
vector<pair<int, int> > pos = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
for(int i = ar; i <= br; i++) {
for(int j = ac; j <= bc; j++) {
if(vis[i][j]) continue ;
if(is[i][j]) continue;
// cout << "esu (" << i << ", " << j << ")\n";
int e = i; int s = j;
int pe, ps;
queue<pair<int, int> > q;
q.push({e, s});
while(q.size()) {
e = q.front().first;
s = q.front().second;
q.pop();
for(auto x : pos) {
pe = x.first + e; ps = x.second + s;
if(pe < ar || pe > br || ps < ac || ps > bc) continue;
if(vis[pe][ps]) continue;
if(is[pe][ps]) continue;
vis[pe][ps] = 1;
q.push({pe, ps});
}
}
ret++;
}
}
// cout << "ret " << ret << endl;
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |