이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |