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 <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
#define all(x) begin(x),end(x)
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define fi first
#define se second
using namespace std; using ll = long long; using ii = pair<int,int>;
const int N = 1e5+3;
int n, k;
char s[N];
set<ii> c, a;
bool make_square(int x, int y) {
rep(i,0,1) rep(j,0,1)
if (not c.count({x+i,y+j})) return false;
return true;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> &s[1];
int x = 0, y = 0;
c.insert({0,0});
rep(i,1,n) {
if (s[i] == 'E') {
c.insert({x,++y});
} else if (s[i] == 'W') {
c.insert({x,--y});
} else if (s[i] == 'N') {
c.insert({++x,y});
} else if (s[i] == 'S') {
c.insert({--x,y});
} else assert(0);
rep(i,-1,1) rep(j,-1,1) {
if (make_square(x+i,y+j)) a.insert({x+i,y+j});
}
}
printf("%d", siz(a));
}
# | 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... |