Submission #946284

# Submission time Handle Problem Language Result Execution time Memory
946284 2024-03-14T13:21:32 Z efedmrlr Furniture (JOI20_furniture) C++17
100 / 100
196 ms 16036 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;


#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 1005;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;

vector<int> diag;
vector<vector<int> > r;

void dfsf(int x, int y) {
    if(x > n || y > m) return;
    if(r[x][y]) return;
    if(r[x][y - 1] && r[x - 1][y]) {
        r[x][y] = 1;
        diag[x + y] += 1;
        dfsf(x + 1, y);
        dfsf(x, y + 1);
    }
}
void dfsb(int x, int y) {
    // cout << "x:" << x << " y:" << y << "\n";
    if(x < 1 || y < 1) return;
    if(r[x][y]) return;
    if(r[x + 1][y] && r[x][y + 1]) {
        r[x][y] = 1;
        diag[x + y] += 1;
        dfsb(x - 1, y); dfsb(x, y - 1);
    } 
}
void blck(int x, int y) {
    
    r[x][y] = 1;
    diag[x + y] += 1;
    dfsf(x + 1, y); dfsf(x, y + 1);
    dfsb(x - 1, y); dfsb(x, y - 1);
}
inline void solve() {
    cin>>n>>m;
    r.assign(n + 5, vector<int>(m + 5, 0));
    diag.assign(n + m + 3, 0);
    for(int i = 0; i <= n; i++) {
        r[i][0] = r[i][m + 1] = 1;
    }
    for(int i = 0; i <= m; i++) {
        r[0][i] = r[n + 1][i] = 1; 
    }
    for(int i = 1; i<=n; i++) {
        for(int j = 1; j <= m; j++) {
            int tmp;
            cin >> tmp;
            if(tmp) {
                if(r[i][j] == 1) continue;
                blck(i, j);
            }
        }
    }
    cin >> q;

    for(int z = 1; z<=q; z++) {
        // for(int i = 1; i <=n; i++) {
        //     for(int j = 1; j <= m; j ++) {
        //         cout << r[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        int x,y;
        cin >> x >> y;
        if(r[x][y]) {
            cout << "1\n";
            continue;
        }
        int sum = x + y;
        // cout << "cnt:" << (min(n, sum - 1) - max(1, sum - m) + 1) << "\n";
        // cout << diag[sum] << "\n";
        if((min(n, sum - 1) - max(1, sum - m) + 1) - diag[sum] > 1) {
            cout << "1\n";
            blck(x, y);
        }
        else {
            cout << "0\n";
        }
    }

}
 
signed main() {

    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 856 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 5 ms 856 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 85 ms 8828 KB Output is correct
13 Correct 48 ms 5992 KB Output is correct
14 Correct 145 ms 13392 KB Output is correct
15 Correct 153 ms 13564 KB Output is correct
16 Correct 158 ms 14804 KB Output is correct
17 Correct 159 ms 15452 KB Output is correct
18 Correct 154 ms 14928 KB Output is correct
19 Correct 159 ms 15952 KB Output is correct
20 Correct 159 ms 16036 KB Output is correct
21 Correct 196 ms 15956 KB Output is correct