답안 #1016845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016845 2024-07-08T13:21:46 Z vjudge1 Nautilus (BOI19_nautilus) C++17
0 / 100
2 ms 600 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int numRow, numCol, numSign;

#define MAX             501
#define MAX_SIGN        5001

char A[MAX][MAX];
char sign[MAX_SIGN];

struct BitSet{
    bitset<MAX> G[MAX];
    int N, M;
    BitSet(){}
    BitSet(int _N, int _M): N(_N), M(_M){}

    void up(void){
        for (int i = 0; i < N - 1; ++i){
            swap(G[i], G[i + 1]);
        }
        G[N - 1].reset();
    }
    void down(void){
        for (int i = N - 1; i > 0; --i){
            swap(G[i], G[i - 1]);
        }
        G[0].reset();
    }
    void left(void){
        for (int i = 0; i < N; ++i){
            G[i] >>= 1;
        }
    }
    void right(void){
        for (int i = 0; i < N; ++i){
            G[i] <<= 1;
        }
    }

};
void __print(const BitSet &a){
    REP(i, a.N) REP(j, a.M){
        cout << a.G[i][j] << " \n"[j == a.M - 1];
    }
    cout << '\n';
}
BitSet OR(const BitSet& a, const BitSet& b){
    BitSet res = a;
    for (int i = 0; i < a.N; ++i){
        res.G[i] |= b.G[i];
    }
    return res;
}
BitSet AND(const BitSet& a, const BitSet& b){
    BitSet res = a;
    for (int i = 0; i < a.N; ++i){
        res.G[i] &= b.G[i];
    }
    return res;
}

void process(void){
    cin >> numRow >> numCol >> numSign;
    BitSet dp(numRow, numCol);
    REP(i, numRow) REP(j, numCol){
        char c; cin >> c;
        dp.G[i][j] = (c == '.');
    }
    REP(i, numSign) cin >> sign[i];

    BitSet cur = dp;
    REP(i, numSign){
        BitSet ndp(numRow, numCol);

        if (sign[i] == 'E' || sign[i] == '?'){
            BitSet now = cur;
            now.right();
            ndp = OR(ndp, now);
        }
        if (sign[i] == 'W' || sign[i] == '?'){
            BitSet now = cur;
            now.left();
            ndp = OR(ndp, now);
        }
        if (sign[i] == 'N' || sign[i] == '?'){
            BitSet now = cur;
            now.up();
            ndp = OR(ndp, now);
        }
        if (sign[i] == 'S' || sign[i] == '?'){
            BitSet now = cur;
            now.down();
            ndp = OR(ndp, now);
        }
        cur = AND(dp, ndp);
    }
    int res = 0;
    for (int i = 0; i < numRow; ++i){
        res += cur.G[i].count();
    }
    cout << res;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    freopen(name".inp", "r", stdin);
    freopen(name".out", "w", stdout);

    process();
}



Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:141:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  141 |     freopen(name".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:142:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  142 |     freopen(name".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -