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>
#define rep(i,a,b) for(int i = a;i <= b;i++)
#define repd(i,a,b) for(int i = a;i >= b;i--)
using namespace std;
const int N = 512;
int r,c,m;
bool a[N][N];
bitset<512> dp[N],temp[N],grid[N];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// ifstream cin ("nautilus.inp");
cin >> r >> c >> m;
rep(i,0,r-1)
{
rep(j,0,c-1)
{
char k;
cin >> k;
if(k == '.')
{
grid[i][c - j - 1] = 1;
dp[i][c - j - 1] = 1;
}
}
}
rep(_,1,m)
{
char k;
cin >> k;
switch(k)
{
case 'N':
{
rep(i,1,r-1)
dp[i-1] = (dp[i] & grid[i-1]);
dp[r-1].reset();
break;
}
case 'E' :
{
rep(i,0,r-1)
{
dp[i] >>= 1;
dp[i] &= grid[i];
}
break;
}
case 'S':
{
repd(i,r-1,1)
dp[i] = (dp[i-1] & grid[i]);
dp[0].reset();
break;
}
case 'W':
{
rep(i,0,r-1)
{
dp[i] <<= 1;
dp[i] &= grid[i];
}
break;
}
default :
{
bitset<512> temp[N];
rep(i,1,r-1) temp[i-1] |= dp[i];
rep(i,0,r-1) temp[i] |= ((dp[i] >> 1) | (dp[i] << 1));
repd(i,r-1,1) temp[i] |= dp[i-1];
rep(i,0,r-1) temp[i] &= grid[i];
rep(i,0,r-1) dp[i] = temp[i];
}
}
}
int ans = 0;
rep(i,0,r-1)
{
rep(j,0,c-1) ans += dp[i][j];
}
cout << ans;
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... |