이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<bitset<500>> row(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
char c;
cin >> c;
if(c == '.'){
row[i][j] = 1;
}
}
}
string s;
cin >> s;
vector<vector<bitset<500>>> dp(k+1, vector<bitset<500>> (n));
for(int i = 0; i < n; i++){
dp[0][i] = row[i];
}
for(int x = 1; x <= k; x++){
for(int i = 0; i < n; i++){
if(s[x-1] == 'E'){
dp[x][i] = (dp[x-1][i]<<1)&row[i];
}
else if(s[x-1] == 'W'){
dp[x][i] = (dp[x-1][i]>>1)&row[i];
}
else if(s[x-1] == 'N' && i+1 < n){
dp[x][i] = dp[x-1][i+1]&row[i];
}
else if(s[x-1] == 'S' && i-1 >= 0){
dp[x][i] = dp[x-1][i-1]&row[i];
}
else if(s[x-1] == '?'){
dp[x][i] |= (dp[x-1][i]<<1);
dp[x][i] |= (dp[x-1][i]>>1);
if(i+1 < n){
dp[x][i] |= dp[x-1][i+1];
}
if(i-1 >= 0){
dp[x][i] |= dp[x-1][i-1];
}
dp[x][i] &= row[i];
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
ans += dp[k][i].count();
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |