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 <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
int x, y, p;
std::vector<std::string> arr;
std::string moves;
int dp[105][105][105];
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
inline bool in_mat(int i, int j) {
return !(i<0||i>=x||j<0||j>=y);
}
int sol(int i, int j, int pos) {
if (!in_mat(i,j)) {
return 0;
}
if (arr[i][j]=='#') {
return 0;
}
if (pos<0) {
return 1;
}
if (dp[i][j][pos]!=-1) {
return dp[i][j][pos];
}
int ret = 0;
switch (moves[pos]) {
case 'N':
ret |= sol(i+1,j,pos-1);
break;
case 'S':
ret |= sol(i-1,j,pos-1);
break;
case 'E':
ret |= sol(i,j-1,pos-1);
break;
case 'W':
ret |= sol(i,j+1,pos-1);
break;
default:
for (int k = 0; k < 4; k++) {
int iv = i+dx[k];
int jv = j+dy[k];
ret |= sol(iv,jv,pos-1);
}
break;
}
return dp[i][j][pos] = ret;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> x >> y >> p;
arr.resize(x);
for (auto& i : arr) {
std::cin >> i;
}
std::cin >> moves;
memset(dp,-1,sizeof(dp));
int ret = 0;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ret += sol(i,j,p-1);
}
}
std::cout << ret << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |