This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ent "\n"
const int maxn = (int)2e5 + 13;
const ll inf = (long long)1e18 + 20;
const int mod = (int)1e9 + 7;
int n,m,k;
char a[1001][1001];
int used[1001][1001];
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
bool check(int i,int j){
if(1 <= i && i <= n && 1 <= j && j <= m && a[i][j] == '.')return 1;
else return 0;
}
map<char,pair<int,int>>mp;
string s;
void bfs(int x,int y){
queue<pair<pair<int,int>,int>>q;
q.push({{x,y},1});
while(q.size()){
pair<pair<int,int>,int>v = q.front();
q.pop();
if(v.second == k + 1){
used[v.first.first][v.first.second] = 1;
// cout << v.first.first << ' ' << v.first.second << ent;
// cout << x << ' ' << y << ent << ent;
continue;
}
for(int i = 0 ; i < 4 ; i ++){
int xx = v.first.first + dx[i],yy = v.first.second + dy[i];
if(check(xx,yy)){
if(s[v.second] == '?')q.push({{xx,yy},v.second + 1});
else{
if(mp[s[v.second]].first == dx[i] && mp[s[v.second]].second == dy[i]){
q.push({{xx,yy},v.second + 1});
// cout << v.first.first << ' ' << v.first.second << ent;
// cout << xx << ' ' << yy << ' ' << dx[i] << ' ' << dy[i] << ' ' << v.second << ent;
}
}
}
}
}
}
void solve(){
cin >> n >> m >> k;
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= m ; j ++){
cin >> a[i][j];
}
}
mp['N'] = {-1,0};
mp['E'] = {0,1};
mp['S'] = {1,0};
mp['W'] = {0,-1};
cin >> s;
s = '+' + s;
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= m ; j ++){
if(a[i][j] == '.'){
int x = i,y = j;
bfs(i,j);
}
}
}
int ans = 0;
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= n ; j ++)ans += used[i][j];
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t --){
solve();
}
return 0;
}
Compilation message (stderr)
nautilus.cpp: In function 'void solve()':
nautilus.cpp:103:9: warning: unused variable 'x' [-Wunused-variable]
103 | int x = i,y = j;
| ^
nautilus.cpp:103:15: warning: unused variable 'y' [-Wunused-variable]
103 | int x = i,y = j;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |