#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma optimize("O3")
typedef int ll;
ll dx[]={1, 0, -1, 0};
ll dy[]={0, 1, 0, -1};
char cad[505][505];
string s;
pair<ll,ll> d(char car)
{
if(car=='N')
return {1,0};
if(car=='S')
return {-1,0};
if(car=='W')
return {0,1};
if(car=='E')
return {0,-1};
}
vector<vector<unordered_map<ll,ll>>> mapa;
ll sol(ll px, ll py, ll p)
{
if(cad[px][py]=='#') return -1;
if(p==s.size()) return 1;
if(mapa[px][py][p]!=0) return mapa[px][py][p];
if(s[p]!='?')
{
pair<ll,ll> car=d(s[p]);
return mapa[px][py][p]=sol(car.first+px,py+car.second,p+1);
}
ll bs=-1;
for(int i=0; i<4; i++){
bs=max(bs,sol(px+dx[i],py+dy[i],p+1));
}
return mapa[px][py][p] = bs;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n,m,k;
cin>>n>>m>>k;
for(int i=0; i<=n+2; i++)
for(int j=0;j<=m+2; j++)
cad[i][j]='#';
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
cin>>cad[i][j];
mapa.assign(505,vector<unordered_map<ll,ll>>(505));
cin>>s;
reverse(s.begin(),s.end());
ll cont=0;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
cont+=max(sol(i,j,0),0);
}
}
cout<<cont;
return 0;
}
Compilation message
nautilus.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
4 | #pragma optimize("O3")
|
nautilus.cpp: In function 'll sol(ll, ll, ll)':
nautilus.cpp:25:9: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(p==s.size()) return 1;
| ~^~~~~~~~~~
nautilus.cpp: In function 'std::pair<int, int> d(char)':
nautilus.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
20 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
51600 KB |
Output is correct |
2 |
Correct |
17 ms |
18524 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
8 ms |
14936 KB |
Output is correct |
5 |
Correct |
8 ms |
15012 KB |
Output is correct |
6 |
Correct |
8 ms |
14424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
51600 KB |
Output is correct |
2 |
Correct |
17 ms |
18524 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
8 ms |
14936 KB |
Output is correct |
5 |
Correct |
8 ms |
15012 KB |
Output is correct |
6 |
Correct |
8 ms |
14424 KB |
Output is correct |
7 |
Correct |
117 ms |
54868 KB |
Output is correct |
8 |
Correct |
23 ms |
20828 KB |
Output is correct |
9 |
Correct |
9 ms |
15688 KB |
Output is correct |
10 |
Correct |
8 ms |
14940 KB |
Output is correct |
11 |
Correct |
7 ms |
14428 KB |
Output is correct |
12 |
Correct |
147 ms |
55636 KB |
Output is correct |
13 |
Correct |
120 ms |
45568 KB |
Output is correct |
14 |
Correct |
74 ms |
34420 KB |
Output is correct |
15 |
Correct |
10 ms |
15708 KB |
Output is correct |
16 |
Correct |
7 ms |
14428 KB |
Output is correct |
17 |
Correct |
184 ms |
55976 KB |
Output is correct |
18 |
Correct |
177 ms |
47784 KB |
Output is correct |
19 |
Correct |
38 ms |
29020 KB |
Output is correct |
20 |
Correct |
17 ms |
19676 KB |
Output is correct |
21 |
Correct |
8 ms |
14684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
51600 KB |
Output is correct |
2 |
Correct |
17 ms |
18524 KB |
Output is correct |
3 |
Correct |
9 ms |
16220 KB |
Output is correct |
4 |
Correct |
8 ms |
14936 KB |
Output is correct |
5 |
Correct |
8 ms |
15012 KB |
Output is correct |
6 |
Correct |
8 ms |
14424 KB |
Output is correct |
7 |
Correct |
117 ms |
54868 KB |
Output is correct |
8 |
Correct |
23 ms |
20828 KB |
Output is correct |
9 |
Correct |
9 ms |
15688 KB |
Output is correct |
10 |
Correct |
8 ms |
14940 KB |
Output is correct |
11 |
Correct |
7 ms |
14428 KB |
Output is correct |
12 |
Correct |
147 ms |
55636 KB |
Output is correct |
13 |
Correct |
120 ms |
45568 KB |
Output is correct |
14 |
Correct |
74 ms |
34420 KB |
Output is correct |
15 |
Correct |
10 ms |
15708 KB |
Output is correct |
16 |
Correct |
7 ms |
14428 KB |
Output is correct |
17 |
Correct |
184 ms |
55976 KB |
Output is correct |
18 |
Correct |
177 ms |
47784 KB |
Output is correct |
19 |
Correct |
38 ms |
29020 KB |
Output is correct |
20 |
Correct |
17 ms |
19676 KB |
Output is correct |
21 |
Correct |
8 ms |
14684 KB |
Output is correct |
22 |
Runtime error |
975 ms |
262144 KB |
Execution killed with signal 9 |
23 |
Halted |
0 ms |
0 KB |
- |