# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221381 | Leonardo_Paes | Nautilus (BOI19_nautilus) | C++17 | 139 ms | 864 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;
const int maxn = 510;
int r, c, m, ans = 0;
bitset<maxn> dp[maxn], mat[maxn], tfg[maxn];
string s;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin >> r >> c >> m;
for(int i=0; i<r; i++){
for(int j=0; j<c; j++){
char a;
cin >> a;
if(a == '.') mat[i][c-j-1] = dp[i][c-j-1] = 1;
}
}
cin >> s;
for(int j=0; j<s.size(); j++){
if(s[j] == 'N'){
for(int i=0; i<r; i++){
if(i+1 < r) dp[i] = (dp[i+1] & mat[i]);
else dp[i].reset();
}
}
if(s[j] == 'S'){
for(int i=r-1; i>=0; i--){
if(i) dp[i] = (dp[i-1] & mat[i]);
else dp[i].reset();
}
}
if(s[j] == 'E'){
for(int i=0; i<r; i++){
dp[i] = ((dp[i] >> 1) & mat[i]);
}
}
if(s[j] == 'W'){
for(int i=0; i<r; i++){
dp[i] = ((dp[i] << 1) & mat[i]);
}
}
if(s[j] == '?'){
for(int i=0; i<r; i++){
tfg[i] = (dp[i] << 1)|(dp[i] >> 1);
if(i) tfg[i] |= dp[i-1];
if(i+1 < r) tfg[i] |= dp[i+1];
tfg[i] &= mat[i];
}
for(int i=0; i<r; i++){
dp[i] = tfg[i];
}
}
}
for(int i=0; i<r; i++) ans += dp[i].count();
cout << ans << endl;
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... |