Submission #314967

#TimeUsernameProblemLanguageResultExecution timeMemory
314967saarang123Nautilus (BOI19_nautilus)C++14
66 / 100
1093 ms1464 KiB
#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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...