#include<bits/stdc++.h>
using namespace std;
int n,m,k,xx[]={0,0,1,-1},yy[]={1,-1,0,0},a[105][105],dp[105][105][105];
char gr[105][105];
string s;
void dfs(int x,int y,int in)
{
if(in==k)
{
a[x][y]=1;
return;
}
if(dp[x][y][in])return;
int tx=x,ty=y;
if(s[in]=='E')ty++;
else if(s[in]=='W')ty--;
else if(s[in]=='N')tx--;
else if(s[in]=='S')tx++;
else
{
for(int i=0;i<4;i++)
{
tx=x+xx[i],ty=y+yy[i];
if(0<=tx&&tx<n&&0<=ty&&ty<m&&gr[tx][ty]=='.')dfs(tx,ty,in+1);
}
return;
}
if(0<=tx&&tx<n&&0<=ty&&ty<m&&gr[tx][ty]=='.')dfs(tx,ty,in+1);
dp[x][y][in]=1;
}
int main()
{
cin>>n>>m>>k;
for(int i=0;i<n;i++)cin>>gr[i];
cin>>s;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(gr[i][j]=='.')dfs(i,j,0);
}
}
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j])ans++;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
4728 KB |
Output is correct |
2 |
Correct |
9 ms |
4728 KB |
Output is correct |
3 |
Correct |
8 ms |
4600 KB |
Output is correct |
4 |
Correct |
8 ms |
4600 KB |
Output is correct |
5 |
Correct |
8 ms |
4088 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
4728 KB |
Output is correct |
2 |
Correct |
9 ms |
4728 KB |
Output is correct |
3 |
Correct |
8 ms |
4600 KB |
Output is correct |
4 |
Correct |
8 ms |
4600 KB |
Output is correct |
5 |
Correct |
8 ms |
4088 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
54 ms |
4728 KB |
Output is correct |
8 |
Correct |
20 ms |
4660 KB |
Output is correct |
9 |
Correct |
10 ms |
4600 KB |
Output is correct |
10 |
Correct |
7 ms |
2936 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Execution timed out |
1086 ms |
552 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
4728 KB |
Output is correct |
2 |
Correct |
9 ms |
4728 KB |
Output is correct |
3 |
Correct |
8 ms |
4600 KB |
Output is correct |
4 |
Correct |
8 ms |
4600 KB |
Output is correct |
5 |
Correct |
8 ms |
4088 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
54 ms |
4728 KB |
Output is correct |
8 |
Correct |
20 ms |
4660 KB |
Output is correct |
9 |
Correct |
10 ms |
4600 KB |
Output is correct |
10 |
Correct |
7 ms |
2936 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Execution timed out |
1086 ms |
552 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |