답안 #449947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
449947 2021-08-02T10:11:09 Z zxcvbnm Nautilus (BOI19_nautilus) C++14
66 / 100
1000 ms 135148 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
char mat[505][505];
bool vis[5005][505][505];
int n, m, k;
string str;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3
bool isValid(int x, int y) {
    if (x >= n || x < 0 || y >= m || y < 0) return false;
    if (mat[x][y] == '#') return false;
    return true;
}
void go(int curr, int x, int y) {
    if (!isValid(x, y) || vis[curr][x][y]) return;
    vis[curr][x][y] = true;
    if (curr == k) return;

    if (str[curr] == '?') {
        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (isValid(nx, ny)) {
                go(curr+1, nx, ny);
            }
        }
    } else {
        switch(str[curr]) {
        case 'N':
            go(curr+1, x+dx[NORTH], y+dy[NORTH]);
            break;
        case 'E':
            go(curr+1, x+dx[EAST], y+dy[EAST]);
            break;
        case 'S':
            go(curr+1, x+dx[SOUTH], y+dy[SOUTH]);
            break;
        case 'W':
            go(curr+1, x+dx[WEST], y+dy[WEST]);
            break;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> mat[i][j];
        }
    }
    cin >> str;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            go(0, i, j);
        }
    }

//    for(int p = 0; p <= k; p++) {
//    if (p != 0) cout << str[p-1] << "\n";
//
//    for(int i = 0; i < n; i++) {
//        for(int j = 0; j < m; j++) {
//            cout << vis[p][i][j] << "";
//        }
//        cout << "\n";
//    }
//    cout << "\n";
//    }

    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cnt += vis[k][i][j];
        }
    }
    cout << cnt << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5324 KB Output is correct
2 Correct 5 ms 4812 KB Output is correct
3 Correct 3 ms 2508 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5324 KB Output is correct
2 Correct 5 ms 4812 KB Output is correct
3 Correct 3 ms 2508 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 844 KB Output is correct
7 Correct 19 ms 5692 KB Output is correct
8 Correct 9 ms 5700 KB Output is correct
9 Correct 5 ms 4428 KB Output is correct
10 Correct 2 ms 2120 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 36 ms 5740 KB Output is correct
13 Correct 35 ms 5956 KB Output is correct
14 Correct 27 ms 5708 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 55 ms 5792 KB Output is correct
18 Correct 41 ms 5736 KB Output is correct
19 Correct 14 ms 5784 KB Output is correct
20 Correct 7 ms 5704 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5324 KB Output is correct
2 Correct 5 ms 4812 KB Output is correct
3 Correct 3 ms 2508 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 844 KB Output is correct
7 Correct 19 ms 5692 KB Output is correct
8 Correct 9 ms 5700 KB Output is correct
9 Correct 5 ms 4428 KB Output is correct
10 Correct 2 ms 2120 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 36 ms 5740 KB Output is correct
13 Correct 35 ms 5956 KB Output is correct
14 Correct 27 ms 5708 KB Output is correct
15 Correct 5 ms 4940 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 55 ms 5792 KB Output is correct
18 Correct 41 ms 5736 KB Output is correct
19 Correct 14 ms 5784 KB Output is correct
20 Correct 7 ms 5704 KB Output is correct
21 Correct 2 ms 1100 KB Output is correct
22 Execution timed out 1097 ms 135148 KB Time limit exceeded
23 Halted 0 ms 0 KB -