Submission #136386

#TimeUsernameProblemLanguageResultExecution timeMemory
136386popovicirobertNautilus (BOI19_nautilus)C++14
66 / 100
1059 ms2944 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast") #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 /*const int MOD = (int) 1e9 + 7; inline int lgput(int a, int b) { int ans = 1; while(b > 0) { if(b & 1) ans = (1LL * ans * a) % MOD; b >>= 1; a = (1LL * a * a) % MOD; } return ans; } inline void mod(int &x) { if(x >= MOD) x -= MOD; } inline void add(int &x, int y) { x += y; mod(x); } inline void sub(int &x, int y) { x += MOD - y; mod(x); } inline void mul(int &x, int y) { x = (1LL * x * y) % MOD; }*/ /*int fact[], invfact[]; inline void prec(int n) { fact[0] = 1; for(int i = 1; i <= n; i++) { fact[i] = (1LL * fact[i - 1] * i) % MOD; } invfact[n] = lgput(fact[n], MOD - 2); for(int i = n - 1; i >= 0; i--) { invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD; } } inline int comb(int n, int k) { if(n < k) return 0; return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD; }*/ using namespace std; const int MAXN = 500; char mat[MAXN + 1][MAXN + 1]; bitset <501> dp[2][MAXN + 1]; int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, j, n, m, k; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m >> k; vector < pair <int, int> > cells; for(i = 1; i <= n; i++) { cin >> mat[i] + 1; for(j = 1; j <= m; j++) { if(mat[i][j] == '.') { cells.push_back({i, j}); } } } for(auto it : cells) { dp[0][it.first][it.second] = 1; } for(int t = 0; t < k; t++) { char ch; cin >> ch; for(i = 1; i <= n; i++) { dp[1 - t & 1][i].reset(); } for(auto it : cells) { i = it.first, j = it.second; if(dp[t & 1][i][j]) { if(i > 0 && (ch == 'N' || ch == '?')) { dp[1 - t & 1][i - 1][j] = 1; } if(j > 0 && (ch == 'W' || ch == '?')) { dp[1 - t & 1][i][j - 1] = 1; } if(i < n && (ch == 'S' || ch == '?')) { dp[1 - t & 1][i + 1][j] = 1; } if(j < m && (ch == 'E' || ch == '?')) { dp[1 - t & 1][i][j + 1] = 1; } } } } int ans = 0; for(auto it : cells) { i = it.first, j = it.second; ans += dp[k & 1][i][j]; } cout << ans; return 0; }

Compilation message (stderr)

nautilus.cpp: In function 'int main()':
nautilus.cpp:78:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin >> mat[i] + 1;
                ~~~~~~~^~~
nautilus.cpp:95:18: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
             dp[1 - t & 1][i].reset();
                ~~^~~
nautilus.cpp:102:26: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                     dp[1 - t & 1][i - 1][j] = 1;
                        ~~^~~
nautilus.cpp:105:26: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                     dp[1 - t & 1][i][j - 1] = 1;
                        ~~^~~
nautilus.cpp:108:26: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                     dp[1 - t & 1][i + 1][j] = 1;
                        ~~^~~
nautilus.cpp:111:26: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
                     dp[1 - t & 1][i][j + 1] = 1;
                        ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...