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 <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
lli f,c,n,d;
lli arr[502][502], dir[8] = {-1,0,1,0,0,1,0,-1};
vector<vector<lli> > pas,nuevo;
char x;
int main()
{
ios_base::sync_with_stdio(false);
cin >> f >> c >> n;
pas.resize(f+2);
nuevo.resize(f+2);
rep(i,0,f+1) {pas[i].resize(c+2); nuevo[i].resize(c+2);}
rep(i,1,f) {
rep(j,1,c) {
cin >> x;
if (x == '.') {
arr[i][j] = 1;
pas[i][j] = 1;
}
else arr[i][j] = 0;
}
}
rep(act,1,n) {
cin >> x;
if (x == 'N') d = 0;
else if (x == 'E') d = 1;
else if (x == 'S') d = 2;
else if (x == 'W') d = 3;
else d = -1;
rep(i,1,f) {
rep(j,1,c) {
if (arr[i][j] == 0) continue;
if (pas[i][j] != act) continue;
rep(k,0,3) {
if (d != -1 && d != k) continue;
nuevo[i + dir[k]][j + dir[k+4]] = act+1;
}
}
}
swap(pas,nuevo);
}
lli sum = 0;
rep(i,1,f) {
rep(j,1,c) {
if (arr[i][j] == 0) continue;
if (pas[i][j] == n+1) sum++;
}
}
cout << sum;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |