| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1344403 | dex111222333444555 | Nautilus (BOI19_nautilus) | C++20 | 187 ms | 796 KiB |
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define dbg(x) "[" #x " = " << x << "]"
using namespace std;
bool M1;
const int mod = 1e9 + 7, infINT = 1e9 + 12313, LOG = 61;
const long long inf = 1e18 + 123213;
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}
const int MAXN = 505;
const int dx[4] = {-1, +1, +0, +0};
const int dy[4] = {+0, +0, -1, +1};
int numRow, numCol, numDir;
char board[MAXN][MAXN];
string dir;
bitset<MAXN > block[MAXN], dp[2][MAXN], blank;
void input(){
cin >> numRow >> numCol >> numDir;
for(int i = 1; i <= numRow; i++)
for(int j = 1; j <= numCol; j++) cin >> board[i][j];
cin >> dir;
}
void solve(){
dir = '_' + dir;
for(int i = 1; i <= numRow; i++)
for(int j = 1; j <= numCol; j++) {
if (board[i][j] == '.'){
dp[0][i][j] = block[i][j] = 1;
}
else{
dp[0][i][j] = block[i][j] = 0;
}
}
int pre = 1, cur = 0;
for(int i = 1; i <= numDir; i++){
swap(pre, cur);
for(int i = 1; i <= numRow; i++){
dp[cur][i] = blank;
}
if (dir[i] == 'E' || dir[i] == '?'){
for(int j = 1; j <= numRow; j++){
dp[cur][j] |= (dp[pre][j] << 1);
}
}
if (dir[i] == 'W' || dir[i] == '?'){
for(int j = 1; j <= numRow; j++){
dp[cur][j] |= (dp[pre][j] >> 1);
}
}
if (dir[i] == 'S' || dir[i] == '?'){
for(int j = 1; j <= numRow; j++){
dp[cur][j] |= (dp[pre][j - 1]);
}
}
if (dir[i] == 'N' || dir[i] == '?'){
for(int j = 1; j <= numRow; j++){
dp[cur][j] |= dp[pre][j + 1];
}
}
for(int j = 1; j <= numRow; j++){
dp[cur][j] &= block[j];
}
}
int res = 0;
for(int i = 1; i <= numRow; i++) res += dp[cur][i].count();
cout << res << '\n';
}
bool M2;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
input();
solve();
cerr << (&M2 - &M1) / 1048576 << " mb\n";
cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
