이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
bool dp[105][105][105];
int r, c, m;
bool get(int x, int y, int k) {
if (x >= r || x < 0 || y >= c || y < 0) {
return false;
}
return dp[x][y][k - 1];
}
int main() {
cin >> r >> c >> m;
int grid[105][105];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
char x;
cin >> x;
if (x == '.') {
grid[i][j] = 1;
dp[i][j][0] = true;
}
else {
grid[i][j] = 0;
}
}
}
string s;
cin >> s;
for (int k = 1; k <= m; k++) {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (grid[i][j] == 0) {
dp[i][j][k] = false;
continue;
}
if (s[k - 1] == 'W') {
dp[i][j][k] = get(i, j + 1, k);
}
if (s[k - 1] == 'E') {
dp[i][j][k] = get(i, j - 1, k);
}
if (s[k - 1] == 'N') {
dp[i][j][k] = get(i + 1, j, k);
}
if (s[k - 1] == 'S') {
dp[i][j][k] = get(i - 1, j, k);
}
if (s[k - 1] == '?') {
dp[i][j][k] = get(i - 1, j, k) || get(i + 1, j, k) || get(i, j - 1, k) || get(i, j + 1, k);
}
//dp[i][j][k] &= dp[i][j][k - 1];
}
}
}
int counter = 0;
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
if(dp[i][j][m]){
counter++;
}
}
}
cout << counter << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |