#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;
dp[x][y][in]=1;
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);
}
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 |
12 ms |
4728 KB |
Output is correct |
2 |
Correct |
8 ms |
4728 KB |
Output is correct |
3 |
Correct |
8 ms |
4604 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 |
12 ms |
4728 KB |
Output is correct |
2 |
Correct |
8 ms |
4728 KB |
Output is correct |
3 |
Correct |
8 ms |
4604 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 |
21 ms |
4728 KB |
Output is correct |
8 |
Correct |
14 ms |
4728 KB |
Output is correct |
9 |
Correct |
12 ms |
4728 KB |
Output is correct |
10 |
Correct |
11 ms |
4088 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
32 ms |
4728 KB |
Output is correct |
13 |
Correct |
37 ms |
4728 KB |
Output is correct |
14 |
Correct |
37 ms |
4728 KB |
Output is correct |
15 |
Correct |
9 ms |
4088 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
47 ms |
4856 KB |
Output is correct |
18 |
Correct |
41 ms |
4728 KB |
Output is correct |
19 |
Correct |
20 ms |
4600 KB |
Output is correct |
20 |
Correct |
10 ms |
4216 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4728 KB |
Output is correct |
2 |
Correct |
8 ms |
4728 KB |
Output is correct |
3 |
Correct |
8 ms |
4604 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 |
21 ms |
4728 KB |
Output is correct |
8 |
Correct |
14 ms |
4728 KB |
Output is correct |
9 |
Correct |
12 ms |
4728 KB |
Output is correct |
10 |
Correct |
11 ms |
4088 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
32 ms |
4728 KB |
Output is correct |
13 |
Correct |
37 ms |
4728 KB |
Output is correct |
14 |
Correct |
37 ms |
4728 KB |
Output is correct |
15 |
Correct |
9 ms |
4088 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
47 ms |
4856 KB |
Output is correct |
18 |
Correct |
41 ms |
4728 KB |
Output is correct |
19 |
Correct |
20 ms |
4600 KB |
Output is correct |
20 |
Correct |
10 ms |
4216 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Runtime error |
36 ms |
9592 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
23 |
Halted |
0 ms |
0 KB |
- |