Submission #543355

# Submission time Handle Problem Language Result Execution time Memory
543355 2022-03-30T11:12:13 Z huB1erTi2 Nautilus (BOI19_nautilus) C++17
0 / 100
0 ms 212 KB
//   _|                                                _|
//   _|  _|    _|    _|    _|_|    _|_|_|      _|_|_|  _|  _|      _|_|      _|_|
//   _|_|      _|    _|  _|_|_|_|  _|    _|  _|_|      _|_|      _|_|_|_|  _|_|_|_|
//   _|  _|    _|    _|  _|        _|    _|      _|_|  _|  _|    _|        _|
//   _|    _|    _|_|_|    _|_|_|  _|_|_|    _|_|_|    _|    _|    _|_|_|    _|_|_|
//                   _|            _|
//               _|_|              _|
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

// #define DEBUG
#ifdef DEBUG
#define dassert(x) assert(x);
#define df(...) printf(__VA_ARGS__)
#else
#define dassert(x)
#define df(...)
#endif

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define ir(x, a, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define sz(x) (ll)x.size()
#define foru(i, n) for (int i = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()

typedef int64_t ll;

int read() {
    int n = 0; bool b = 0; char c = getchar();
    for (; !ir(c, '0', '9'); c = getchar()) b = (c == '-');
    for (; ir(c, '0', '9'); c = getchar()) n = 10*n + (c-'0');
    if (b) return -n;
    return n;
}

// const int N = 502;
const int N = 20;

int n, m, k;
struct area {
    vec<bitset<N>> v;
    
    area() {
        v.resize(n+2);
    }
    
    void operator &=(const area& other) {
        foru (i, n+2) {
            v[i] &= other.v[i];
        }
    }
    
    void operator |=(const area& other) {
        foru (i, n+2) {
            v[i] |= other.v[i];
        }
    }
    
    int count() {
        int s = 0;
        for (auto& b : v) {
            s += b.count();
        }
        return s;
    }
};

area movey(const area& src, int by) {
    area a;
    for (int i = 1; i <= n; ++i) {
        a.v[i] = src.v[i+by];
    }
    return a;
}

area movex(area a, int by) {
    for (int i = 1; i <= n; ++i) {
        if (by < 0) {
            a.v[i] <<= -by;
        } else {
            a.v[i] >>= by;
        }
    }
    // for (int i = 0; i <= n+1; ++i) {
    //     cout << a.v[i] << "\n";
    // }
    // cout << "\n";
    return a;
}

int main() {
    df("debug mode\n");
#ifndef DEBUG
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
    cin >> n >> m >> k;
    area a;
    for (int i = 1; i <= n; ++i) {
        string s;
        cin >> s;
        for (int j = 1; j <= m; ++j) {
            a.v[i][j] = (s[j-1] == '.');
        }
    }
    
    area full;
    // foru (i, m+2) foru (j, m+2) full.v[i][j] = 1;
    
    string s;
    cin >> s;
    
    // foru (i, m+2) {
    //     a.v[0][i] = a.v[n+1][i] = 1;
    // }
    // foru (i, n+2) {
    //     a.v[i][0] = a.v[i][m+1] = 1;
    // }
    
    const area orig = a;
    // for (int i = 0; i <= n+1; ++i) {
    //     cout << a.v[i] << "\n";
    // }
    // cout << "\n";
    for (int i = 0; i <= k-1; ++i) {
        char c = s[i];
        area aa = orig;
        if (c == 'N') {
            aa &= movey(a, 1);
        } else if (c == 'S') {
            aa &= movey(a, -1);
        } else if (c == 'E') {
            aa &= movex(a, -1);
        } else if (c == 'W') {
            aa &= movex(a, 1);
        } else if (c == '?') {
            area b = movey(a, 1);
            b |= movey(a, -1);
            b |= movex(a, 1);
            b |= movex(a, -1);
            aa &= b;
        }
        a = aa;
        // a &= full;
        // for (int i = 0; i <= n+1; ++i) {
        //     cout << a.v[i] << "\n";
        // }
        // cout << "\n";
        
    }
    cout << a.count() << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -