# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088923 | Cadoc | Nautilus (BOI19_nautilus) | C++14 | 166 ms | 1112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define el cout << '\n'
#define N 505
int n, m, k;
string s;
char c[N][N];
bitset<N> dp[2][N], f[N];
void Solve(){
cin >> n >> m >> k;
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) cin >> c[i][j];
cin >> s; s = ' ' + s;
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) dp[0][i][j] = f[i][j] = (c[i][j] == '.');
for(int t=1; t<=k; ++t){
char x = s[t];
if(x == 'N') for(int i=n-1; i; --i) dp[1][i] |= dp[0][i+1], dp[1][i] &= f[i];
if(x == 'S') for(int i=2; i<=n; ++i) dp[1][i] |= dp[0][i-1], dp[1][i] &= f[i];
if(x == 'W') for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]>>1), dp[1][i] &= f[i];
if(x == 'E') for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]<<1), dp[1][i] &= f[i];
if(x == '?'){
for(int i=n-1; i; --i) dp[1][i] |= dp[0][i+1], dp[1][i] &= f[i];
for(int i=2; i<=n; ++i) dp[1][i] |= dp[0][i-1], dp[1][i] &= f[i];
for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]>>1), dp[1][i] &= f[i];
for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]<<1), dp[1][i] &= f[i];
}
for(int i=1; i<=n; ++i) dp[0][i] = dp[1][i], dp[1][i].reset();
}
int Ans = 0;
for(int i=1; i<=n; ++i) Ans += dp[0][i].count();
cout << Ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define NAME "TAUCHIEN"
if(fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
Solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |