답안 #1086879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086879 2024-09-11T16:17:11 Z steveonalex Furniture (JOI20_furniture) C++17
0 / 100
2 ms 544 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double cur = rngesus(0, MASK(60) - 1);
    cur /= MASK(60) - 1;
    return l + cur * (r - l);
}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

int main(void){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    clock_t start = clock();

    int n, m; cin >> n >> m;

    int grid[n + 2][m + 2];
    memset(grid, 0, sizeof grid);

    for(int i = 1; i<=n; ++i) for(int j = 1; j<=m; ++j) cin >> grid[i][j];

    int nxt[n+2][m+2], pre[n+2][m+2];;
    for(int i = 0; i<=n+1; ++i) for(int j = 0; j<=m+1; ++j) {
        nxt[i][j] = m+1;
        pre[i][j] = 0;
    }
    for(int i = 1; i<=n; ++i){
        for(int j = m; j>=0; --j){
            nxt[i][j] = nxt[i][j+1];
            if (grid[i][j]) nxt[i][j] = j;
        }
        for(int j = 1; j<=m+1; ++j){
            pre[i][j] = pre[i][j-1];
            if (grid[i][j]) pre[i][j] = j;
        }
    }

    int L[n+2], R[n+2];
    // L: unreachable left part, R: unreachable right part
    L[n+1] = m, R[0] = 1;
    for(int i = 1; i<=n; ++i){
        R[i] = nxt[i][R[i-1] - 1];
    }
    for(int i = n; i>=1; --i){
        L[i] = pre[i][L[i+1] + 1];
    }

    int q; cin >> q;
    while(q--){
        int x, y; cin >> x >> y;
        int _L[n+2], _R[n+2];
        for(int i = 0; i<=n+1; ++i) {
            _L[i] = L[i];
            _R[i] = R[i];
        }

        if (y >= _R[x-1] - 1) minimize(_R[x], y); 
        if (y <= _L[x+1] + 1) maximize(_L[x], y);
        for(int i = x+1; i <= n; ++i){
            _R[i] = nxt[i][_R[i-1] - 1];
            if (_R[i] == R[i]) break;
        }
        for(int i = x-1; i>=1; --i){
            _L[i] = pre[i][_L[i+1] + 1];
            if (_L[i] == L[i]) break;
        }

        bool check = true;
        for(int i = 1; i<=n; ++i) if (_L[i] >= _R[i]) check = false;

        if (check == false){
            cout << 0 << "\n";
        } 
        else{
            cout << 1 << "\n";
            for(int i = 0; i<=n+1; ++i) {
                L[i] = _L[i];
                R[i] = _R[i];
            }
            nxt[x][y] = pre[x][y] = y;
            for(int j = y-1; j >= 0; --j) {
                minimize(nxt[x][j], nxt[x][j+1]); 
            }
            for(int j = y+1; j <= m+1; ++j){
                maximize(pre[x][j], pre[x][j-1]);
            }
        }
    }

 
    cerr << "Time elapsed: " << clock() - start << " ms\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 544 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 544 KB Output isn't correct
3 Halted 0 ms 0 KB -