답안 #314967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314967 2020-10-21T18:10:25 Z saarang123 Nautilus (BOI19_nautilus) C++14
66 / 100
1000 ms 1464 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair

template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int N = 102;
vector<array<int, 2>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
bool dp[N][N][N], is[N][N];
int n, m, k;
char a[N][N];
string s;

void f(int i, int j, int x) {
    if(i < 1 || i > n || j < 1 || j > m || x > k) return;
    if(dp[i][j][x]) return;
    dp[i][j][x] = 1;
    if(a[i][j] == '#') return;
    if(x == k) {
        return void(is[i][j] = true);
    }
    if(s[x] == 'N') f(i - 1, j, x + 1);
    else if(s[x] == 'S') f(i + 1, j, x + 1);
    else if(s[x] == 'E') f(i, j + 1, x + 1);
    else if(s[x] == 'W') f(i, j - 1, x + 1);
    else {
        for(array<int, 2> dx : dir) {
            f(i + dx[0], j + dx[1], x + 1);
        }
    }
}

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int i, j;
    cin >> n >> m >> k;
    for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) cin >> a[i][j];
    cin >> s;
    memset(dp, 0, sizeof dp);
    for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) f(i, j, 0);
    int ans = 0;
    for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) ans += is[i][j];
    //for(i = 1; i <= n; i++) { for(j = 1; j <= m; j++) cout << is[i][j] << " "; cout << "\n"; }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1408 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 2 ms 1408 KB Output is correct
4 Correct 2 ms 1400 KB Output is correct
5 Correct 2 ms 1408 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1408 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 2 ms 1408 KB Output is correct
4 Correct 2 ms 1400 KB Output is correct
5 Correct 2 ms 1408 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 11 ms 1408 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 2 ms 1408 KB Output is correct
11 Correct 2 ms 1408 KB Output is correct
12 Correct 24 ms 1408 KB Output is correct
13 Correct 24 ms 1408 KB Output is correct
14 Correct 19 ms 1408 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
16 Correct 2 ms 1408 KB Output is correct
17 Correct 30 ms 1408 KB Output is correct
18 Correct 33 ms 1464 KB Output is correct
19 Correct 12 ms 1440 KB Output is correct
20 Correct 5 ms 1440 KB Output is correct
21 Correct 2 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1408 KB Output is correct
2 Correct 1 ms 1408 KB Output is correct
3 Correct 2 ms 1408 KB Output is correct
4 Correct 2 ms 1400 KB Output is correct
5 Correct 2 ms 1408 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 11 ms 1408 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 2 ms 1408 KB Output is correct
11 Correct 2 ms 1408 KB Output is correct
12 Correct 24 ms 1408 KB Output is correct
13 Correct 24 ms 1408 KB Output is correct
14 Correct 19 ms 1408 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
16 Correct 2 ms 1408 KB Output is correct
17 Correct 30 ms 1408 KB Output is correct
18 Correct 33 ms 1464 KB Output is correct
19 Correct 12 ms 1440 KB Output is correct
20 Correct 5 ms 1440 KB Output is correct
21 Correct 2 ms 1408 KB Output is correct
22 Execution timed out 1093 ms 768 KB Time limit exceeded
23 Halted 0 ms 0 KB -