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>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #pragma GCC target ("avx,avx2,fma")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define setp fixed<<setprecision
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
const ll mod=(1ll<<31)-1;
const ld eps=1e-8;
const ll MAXLONG=9223372036854775807;
const ll MINLONG=-9223372036854775807;
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N=1e5+5;
int n, m, k, ans;
string s;
bitset<505>a[505], dp[5005][505];
int main()
{
SPEED;
cin>>n>>m>>k;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
char x; cin>>x;
if(x=='.') a[i][j]=1, dp[0][i][j]=1;
}
}
cin>>s;
for(int i=1; i<=k; i++)
{
for(int j=0; j<n; j++)
{
if(s[i-1]=='N') dp[i][j]=dp[i-1][j+1]&a[j];
else if(s[i-1]=='S') dp[i][j]=dp[i-1][j-1]&a[j];
else if(s[i-1]=='W') dp[i][j]=(dp[i-1][j]>>1)&a[j];
else if(s[i-1]=='E') dp[i][j]=(dp[i-1][j]<<1)&a[j];
else dp[i][j]=(dp[i-1][j+1]|dp[i-1][j-1]|(dp[i-1][j]>>1)|(dp[i-1][j]<<1))&a[j];
}
}
for(int i=0; i<n; i++)
{
ans+=dp[k][i].count();
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |