답안 #1015425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015425 2024-07-06T10:37:43 Z phoenix Nautilus (BOI19_nautilus) C++17
100 / 100
211 ms 860 KB
#include <bits/stdc++.h>

using namespace std;

struct bitMatrix {
    bitset<500> a[500];
    int n, m;
    bitMatrix() {}
    bitMatrix(int n, int m) : n(n), m(m) {}
    bitMatrix(vector<vector<bool>> st) {
        n = (int)st.size();
        m = (int)st[0].size();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                a[i][j] = st[i][j];
    }
    void move_up() {
        for (int i = 0; i < n - 1; i++)     
            swap(a[i], a[i + 1]);
        a[n - 1].reset();
    }
    void move_down() {
        for (int i = n - 1; i > 0; i--)
            swap(a[i - 1], a[i]);
        a[0].reset();
    }
    void move_left() {
        for (int i = 0; i < n; i++)
            a[i] >>= 1; 
    }
    void move_right() {
        for (int i = 0; i < n; i++)
            a[i] <<= 1;
    }
    void print() {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++)
                cout << a[i][j];
            cout << '\n';
        }
        cout << '\n';
    }
};

bitMatrix OR(const bitMatrix &a, const bitMatrix &b) {
    assert(a.n == b.n && a.m == b.m);
    bitMatrix res = a;
    for (int i = 0; i < res.n; i++)
        res.a[i] = res.a[i] | b.a[i];
    return res;
}
bitMatrix AND(const bitMatrix &a, const bitMatrix &b) {
    assert(a.n == b.n && a.m == b.m);
    bitMatrix res = a;
    for (int i = 0; i < res.n; i++)
        res.a[i] = res.a[i] & b.a[i];
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, L;
    cin >> n >> m >> L;
    bitMatrix a(n, m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            char c;
            cin >> c;
            a.a[i][j] = (c == '.');
        }
    bitMatrix cur = a;

    for (int it = 0; it < L; it++) {
        char c;
        cin >> c;
        if (c == 'N') {
            cur.move_up();
            cur = AND(cur, a);
        }
        if (c == 'S') {
            cur.move_down();
            cur = AND(cur, a);
        }
        if (c == 'W') {
            cur.move_left();
            cur = AND(cur, a);
        }
        if (c == 'E') {
            cur.move_right();
            cur = AND(cur, a);
        }
        if (c == '?') {
            bitMatrix b(n, m), c;
            
            c = cur; 
            c.move_up();
            b = OR(b, c);
            
            c = cur;
            c.move_down();
            b = OR(b, c);

            c = cur; 
            c.move_left();
            b = OR(b, c);

            c = cur;
            c.move_right();
            b = OR(b, c);

            cur = AND(b, a);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += cur.a[i].count();
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 628 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 628 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 616 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Correct 92 ms 856 KB Output is correct
23 Correct 91 ms 600 KB Output is correct
24 Correct 87 ms 860 KB Output is correct
25 Correct 91 ms 852 KB Output is correct
26 Correct 89 ms 836 KB Output is correct
27 Correct 157 ms 856 KB Output is correct
28 Correct 161 ms 856 KB Output is correct
29 Correct 159 ms 860 KB Output is correct
30 Correct 156 ms 856 KB Output is correct
31 Correct 156 ms 856 KB Output is correct
32 Correct 209 ms 600 KB Output is correct
33 Correct 211 ms 604 KB Output is correct
34 Correct 207 ms 836 KB Output is correct
35 Correct 206 ms 604 KB Output is correct
36 Correct 202 ms 604 KB Output is correct