Submission #1012317

#TimeUsernameProblemLanguageResultExecution timeMemory
1012317androNautilus (BOI19_nautilus)C++14
0 / 100
6 ms8540 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m >> q; char a[n + 1][m + 1]; for(int i = 0; i <= n; i++) { for(int j = 0; j <= m; j++) { a[i][j] = '#'; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a[i][j]; } } char b[q + 1]; for(int i = 1; i <= q; i++) { cin >> b[i]; } int dp[q + 1][n + 1][m + 1]; for(int i = 0; i <= q; i++) { for(int j = 0; j <= n; j++) { for(int k = 0; k <= m; k++) { dp[i][j][k] = 0; } } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(a[i][j] == '.') { dp[0][i][j] = 1; } } } for(int i = 1; i <= q; i++) { if(b[i] == '?') { for(int j = 1; j <= n; j++) { for(int k = 1; k <= m; k++) { if(a[j][k] == '#') { continue; } if(a[j - 1][k] != '#') dp[i][j][k] |= dp[i - 1][j - 1][k]; if(a[j + 1][k] != '#') dp[i][j][k] |= dp[i - 1][j + 1][k]; if(a[j][k - 1] != '#') dp[i][j][k] |= dp[i - 1][j][k - 1]; if(a[j][k + 1] != '#') dp[i][j][k] |= dp[i - 1][j][k + 1]; } } } else { if(b[i] == 'N') { for(int j = 1; j <= n; j++) { for(int k = 1; k <= m; k++) { if(a[j][k] == '#') { continue; } if(a[j - 1][k] != '#') dp[i][j][k] |= dp[i - 1][j - 1][k]; } } } else if(b[i] == 'W') { for(int j = 1; j <= n; j++) { for(int k = 1; k <= m; k++) { if(a[j][k] == '#') { continue; } if(a[j][k - 1] != '#') dp[i][j][k] |= dp[i - 1][j][k - 1]; } } } else if(b[i] == 'S') { for(int j = 1; j <= n; j++) { for(int k = 1; k <= m; k++) { if(a[j][k] == '#') { continue; } if(a[j + 1][k] != '#') dp[i][j][k] |= dp[i - 1][j + 1][k]; } } } else { for(int j = 1; j <= n; j++) { for(int k = 1; k <= m; k++) { if(a[j][k] == '#') { continue; } if(a[j][k + 1] != '#') dp[i][j][k] |= dp[i - 1][j][k + 1]; } } } } } int ans = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { //cout << dp[q][i][j] << " "; ans += dp[q][i][j]; } //cout << endl; } cout << ans; // levo ispod }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...