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 = 112;
int r,c,m,dp[N][N],temp[N][N],grid[N][N];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// ifstream cin ("nautilus.inp");
cin >> r >> c >> m;
rep(i,1,r)
rep(j,1,c)
{
char k;
cin >> k;
dp[i][j] = (k == '.');
grid[i][j] = dp[i][j];
}
rep(_,1,m)
{
char k;
cin >> k;
switch(k)
{
case 'N':
{
rep(i,1,r)
rep(j,1,c)
temp[i][j] = dp[i][j];
rep(i,1,r)
rep(j,1,c)
if(grid[i][j])temp[i][j] = dp[i+1][j];
rep(i,1,r)
rep(j,1,c)
dp[i][j] = temp[i][j];
break;
}
case 'E' :
{
rep(i,1,r)
rep(j,1,c)
temp[i][j] = dp[i][j];
rep(i,1,r)
rep(j,1,c)
if(grid[i][j])temp[i][j] = dp[i][j-1];
rep(i,1,r)
rep(j,1,c)
dp[i][j] = temp[i][j];
break;
}
case 'S':
{
rep(i,1,r)
rep(j,1,c)
temp[i][j] = dp[i][j];
rep(i,1,r)
rep(j,1,c)
if(grid[i][j])temp[i][j] = dp[i-1][j];
rep(i,1,r)
rep(j,1,c)
dp[i][j] = temp[i][j];
break;
}
case 'W':
{
rep(i,1,r)
rep(j,1,c)
temp[i][j] = dp[i][j];
rep(i,1,r)
rep(j,1,c)
if(grid[i][j])temp[i][j] = dp[i][j+1];
rep(i,1,r)
rep(j,1,c)
dp[i][j] = temp[i][j];
break;
}
default :
{
rep(i,1,r)
rep(j,1,c)
temp[i][j] = dp[i][j];
rep(i,1,r)
rep(j,1,c)
if(grid[i][j])temp[i][j] = (dp[i-1][j] || dp[i+1][j] || dp[i][j-1] || dp[i][j+1]);
rep(i,1,r)
rep(j,1,c)
dp[i][j] = temp[i][j];
}
}
}
int ans = 0;
rep(i,1,r)
rep(j,1,c) 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... |