# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377656 | cpp219 | Nautilus (BOI19_nautilus) | C++14 | 330 ms | 179308 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.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 500 + 9;
const ll inf = 1e16 + 7;
char a[N][N];
ll n,m,sz;
string s;
bitset<520> dp[N][5200],sea[N],x;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>m>>sz;
for (ll i = 1;i <= n;i++)
for (ll j = 1;j <= m;j++){
cin>>a[i][j];
if (a[i][j] == '.') sea[i][j] = dp[i][0][j] = 1;
else sea[i][j] = dp[i][0][j] = 0;
}
cin>>s; s = " " + s;
for (ll t = 1;t <= sz;t++){
for (ll i = 1;i <= n;i++){
if (s[t] == 'N') dp[i][t] = (dp[i + 1][t - 1]);
if (s[t] == 'S') dp[i][t] = (dp[i - 1][t - 1]);
if (s[t] == 'E') dp[i][t] = ((dp[i][t - 1] << 1));
if (s[t] == 'W') dp[i][t] = ((dp[i][t - 1] >> 1));
if (s[t] == '?')
dp[i][t] = ((dp[i][t - 1] << 1)|(dp[i][t - 1] >> 1)|(dp[i + 1][t - 1])|(dp[i - 1][t - 1]));
dp[i][t] &= sea[i]; dp[i][t] &= sea[i];
//for (ll j = 1;j <= m;j++) cout<<dp[i][t][j]; exit(0);
}
}
ll ans = 0;
for (ll i = 1;i <= n;i++){
for (ll j = 1;j <= m;j++){
if (dp[i][sz][j]) ans++;
//cout<<dp[i][sz][j];
}
//cout<<"\n";
}
cout<<ans;
}
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... |