답안 #1037033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037033 2024-07-27T22:34:19 Z ArthuroWich Nautilus (BOI19_nautilus) C++17
100 / 100
277 ms 1144 KB
#include <bits/stdc++.h>
using namespace std;
int r, c, m;
bitset<505> dpx[2][505], dpy[2][505], validx[505], validy[505], zero; // row, column
char grid[505][505];
bool isvalid(int i, int j) {
    return !(i < 0 || j < 0 || i >= r || j >= c);
}
void solve() {
    string s;
    cin >> r >> c >> m; 
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> grid[i][j];
            if (grid[i][j] != '#') {
                dpx[0][i][j] = validx[i][j] = 1; 
                dpy[0][j][i] = validy[j][i] = 1;
            }
        }
    }
    cin >> s;
    for (int i = 0; i < m; i++) {
        for (int x = 0; x < r; x++) {
            if (isvalid(x-1, 0) && (s[i] == 'N' || s[i] == '?')) {
                dpx[1][x-1] |= dpx[0][x];
            }
            if (isvalid(x+1, 0) && (s[i] == 'S' || s[i] == '?')) {
                dpx[1][x+1] |= dpx[0][x];
            }
            if (isvalid(0, 0) && (s[i] == 'W' || s[i] == '?')) {
                dpx[1][x] |= (dpx[0][x]>>1);
            }
            if (isvalid(0, 0) && (s[i] == 'E' || s[i] == '?')) {
                dpx[1][x] |= (dpx[0][x]<<1);
            }
        }
        for (int y = 0; y < c; y++) {
            if (isvalid(0, 0) && (s[i] == 'N' || s[i] == '?')) {
                dpy[1][y] |= (dpy[0][y]>>1);
            }
            if (isvalid(0, 0) && (s[i] == 'S' || s[i] == '?')) {
                dpy[1][y] |= (dpy[0][y]<<1);
            }
            if (isvalid(0, y-1) && (s[i] == 'W' || s[i] == '?')) {
                dpy[1][y-1] |= dpy[0][y];
            }
            if (isvalid(0, y+1) && (s[i] == 'E' || s[i] == '?')) {
                dpy[1][y+1] |= dpy[0][y];
            }
        }
        for (int x = 0; x < r; x++) {
            dpx[1][x] &= validx[x];
            dpx[0][x] = dpx[1][x];
            dpx[1][x] &= zero; 
        }
        for (int y = 0; y < c; y++) {
            dpy[1][y] &= validy[y]; 
            dpy[0][y] = dpy[1][y];
            dpy[1][y] &= zero;
        }
    }
    int ans = 0;
    for (int x = 0; x < r; x++) {
        for (int y = 0; y < c; y++) {
            if (dpx[0][x][y] || dpy[0][y][x]) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 576 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 360 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 576 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 392 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 360 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 166 ms 1136 KB Output is correct
23 Correct 151 ms 1140 KB Output is correct
24 Correct 157 ms 1140 KB Output is correct
25 Correct 239 ms 1116 KB Output is correct
26 Correct 155 ms 1116 KB Output is correct
27 Correct 223 ms 1112 KB Output is correct
28 Correct 199 ms 1116 KB Output is correct
29 Correct 234 ms 1116 KB Output is correct
30 Correct 217 ms 1112 KB Output is correct
31 Correct 200 ms 1116 KB Output is correct
32 Correct 249 ms 1112 KB Output is correct
33 Correct 270 ms 1136 KB Output is correct
34 Correct 254 ms 1136 KB Output is correct
35 Correct 277 ms 1144 KB Output is correct
36 Correct 238 ms 1116 KB Output is correct