#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 510;
int r, c, m;
string str;
bool arr[MAX][MAX];
bool dp[MAX][MAX], newdp[MAX][MAX];
int res;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>r>>c>>m;
FOR(i, 1, r, 1){
FOR(j, 1, c, 1){
char ch;
cin>>ch;
if(ch == '.') dp[i][j] = arr[i][j] = 1;
}
}
cin>>str;
for(char i : str){
vector<pii> dd;
if(i == 'W') dd.eb(0, -1);
if(i == 'E') dd.eb(0, 1);
if(i == 'N') dd.eb(-1, 0);
if(i == 'S') dd.eb(1, 0);
if(i == '?'){
dd.eb(0, -1);
dd.eb(0, 1);
dd.eb(-1, 0);
dd.eb(1, 0);
}
FOR(i, 1, r, 1){
FOR(j, 1, c, 1){
newdp[i][j] = 0;
}
}
FOR(i, 1, r, 1){
FOR(j, 1, c, 1){
if(dp[i][j] == 0) continue;
for(pii d : dd){
int ii = i + d.F, jj = j + d.S;
if(arr[ii][jj] == 1) newdp[ii][jj] = 1;
}
}
}
FOR(i, 1, r, 1){
FOR(j, 1, c, 1){
dp[i][j] = newdp[i][j];
}
}
}
FOR(i, 1, r, 1){
FOR(j, 1, c, 1){
res += dp[i][j];
}
}
cout<<res<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
9 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
488 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
15 ms |
460 KB |
Output is correct |
13 |
Correct |
14 ms |
460 KB |
Output is correct |
14 |
Correct |
14 ms |
492 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
17 ms |
456 KB |
Output is correct |
18 |
Correct |
19 ms |
500 KB |
Output is correct |
19 |
Correct |
10 ms |
460 KB |
Output is correct |
20 |
Correct |
4 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
9 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
488 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
15 ms |
460 KB |
Output is correct |
13 |
Correct |
14 ms |
460 KB |
Output is correct |
14 |
Correct |
14 ms |
492 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
17 ms |
456 KB |
Output is correct |
18 |
Correct |
19 ms |
500 KB |
Output is correct |
19 |
Correct |
10 ms |
460 KB |
Output is correct |
20 |
Correct |
4 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Execution timed out |
1084 ms |
1228 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |