#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define forik(x) ll i = 1; i <= x; i++
// (a mod 1e9) / (b mod 1e9) = a * (b^1e9)
using namespace std;
ll a, b, c, e, t, n, m, k;
char p[2001][2001];
string s;
void rec (ll x, ll y, ll a = 0){
// cout << a;
if (p[x][y] == '#'){
return;
}
if (a == k){
b++;
}
if (s[a] == 'N'){
rec (x, y - 1, a + 1);
}
else if (s[a] == 'S'){
rec (x, y + 1, a + 1);
}
else if (s[a] == 'W'){
rec (x - 1, y, a + 1);
}
else if (s[a] == 'E'){
rec (x + 1, y, a + 1);
}
else{
rec (x + 1, y, a + 1);
rec (x, y - 1, a + 1);
rec (x - 1, y, a + 1);
rec (x, y + 1, a + 1);
}
}
signed main (){
//freopen (".in", "r", stdin);
freopen (".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
// swap (n, m);
for (int i = 0; i <= n + 1; i++){
for (int y = 0; y <= m + 1; y++){
p[i][y] = '#';
}
}
for (int i = 1; i <= n; i++){
for (int y = 1; i <= m; y++){
cin >> p[i][y];
}
}
cin >> s;
for (int i = 1; i <= n; i++){
for (int y = 1; y <= m; y++){
if (p[i][y] != '#'){
rec (i, y);
}
}
}
cout << b;
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:53:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen (".out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
2652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
2652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
2652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |