이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define left (h*2),l,(l + r)/2
#define right (h*2+1),(l+r)/2 + 1,r
#define pii pair <int,int>
using namespace std;
const int N = 505;
char a[N][N];
vector <pii> neighbours = {{0,1}, {0,-1}, {1,0}, {-1,0}};
int n,m;
bitset <501> dpold[N],dpnew[N];
bool valid(int x,int y){
return (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] == '.');
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int k;
cin>>n>>m>>k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
cin >> a[i][j];
if (a[i][j] == '.') dpold[i][j] = 1;
}
string s;
cin>>s;
map <char,pii> mp;
mp['N'] = {-1,0};
mp['S'] = {1,0};
mp['E'] = {0,+1};
mp['W'] = {0,-1};
for (int i = 0; i < k; i++){
for (int x = 1; x <= n; x++){
for (int y = 1; y <= m; y++){
if (!dpold[x][y]) continue;
if (s[i] != '?'){
int dx = mp[s[i]].f,dy = mp[s[i]].s;
int X = x + dx,Y = y + dy;
if (valid(X,Y)) dpnew[X][Y] = 1;
continue;
}
for (auto [dx,dy]: neighbours){
int X = x + dx,Y = y + dy;
if (valid(X,Y)) dpnew[X][Y] = 1;
}
}
}
for (int x=1;x<=n; x++)
dpold[x] = dpnew[x],dpnew[x] = 0;
}
int ans=0;
for (int i = 1; i <= n; i++)
ans += dpold[i].count();
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |