Submission #361314

# Submission time Handle Problem Language Result Execution time Memory
361314 2021-01-29T09:04:33 Z Seanliu Furniture (JOI20_furniture) C++14
100 / 100
3017 ms 26476 KB
#include <iostream>
#include <vector>
using namespace std;

const int maxN = 1e3 + 326;
int N, M, levels[maxN * 2], indeg[maxN][maxN], outdeg[maxN][maxN], Q, y, x;
bool has[maxN][maxN]; //id of (i, j) is i * M + j
bool isIn[maxN][maxN], vis[maxN][maxN];

void dfs(int i = 1, int j = 1){
    if(i > N || j > M || has[i][j]) return;
    vis[i][j] = true;
    if(i == N && j == M){
        isIn[i][j] = true;
        return;
    }
    if(!vis[i + 1][j]) dfs(i + 1, j);
    if(!vis[i][j + 1]) dfs(i, j + 1);
    isIn[i][j] = isIn[i + 1][j] | isIn[i][j + 1];
}

void rem(int i, int j){
    if(!isIn[i][j]) return;
    levels[i + j]--;
    isIn[i][j] = false;
    indeg[i + 1][j]--;
    indeg[i][j + 1]--;
    outdeg[i - 1][j]--;
    outdeg[i][j - 1]--;
    if(isIn[i + 1][j] && !indeg[i + 1][j]) rem(i + 1, j);
    if(isIn[i][j + 1] && !indeg[i][j + 1]) rem(i, j + 1);
    if(isIn[i - 1][j] && !outdeg[i - 1][j]) rem(i - 1, j);
    if(isIn[i][j - 1] && !outdeg[i][j - 1]) rem(i, j - 1);
}

int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) cin >> has[i][j];
    dfs();
    for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) if(isIn[i][j]){
        levels[i + j]++;
        indeg[i + 1][j]++;
        indeg[i][j + 1]++;
        outdeg[i - 1][j]++;
        outdeg[i][j - 1]++;
    }
    //for(int i = 1; i <= N + M; i++) cout << levels[i] << endl;
    cin >> Q;
    while(Q--){
        cin >> y >> x;
        if(!isIn[y][x]){
            cout << 1 << '\n';
            continue;
        }
        if(levels[y + x] == 1){
            cout << 0 << '\n';
            continue;
        } else cout << 1 <<'\n';
        rem(y, x);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1292 KB Output is correct
2 Correct 11 ms 1644 KB Output is correct
3 Correct 13 ms 1516 KB Output is correct
4 Correct 23 ms 1644 KB Output is correct
5 Correct 25 ms 1772 KB Output is correct
6 Correct 31 ms 1792 KB Output is correct
7 Correct 30 ms 1772 KB Output is correct
8 Correct 29 ms 1772 KB Output is correct
9 Correct 30 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1292 KB Output is correct
2 Correct 11 ms 1644 KB Output is correct
3 Correct 13 ms 1516 KB Output is correct
4 Correct 23 ms 1644 KB Output is correct
5 Correct 25 ms 1772 KB Output is correct
6 Correct 31 ms 1792 KB Output is correct
7 Correct 30 ms 1772 KB Output is correct
8 Correct 29 ms 1772 KB Output is correct
9 Correct 30 ms 1772 KB Output is correct
10 Correct 76 ms 1516 KB Output is correct
11 Correct 19 ms 1132 KB Output is correct
12 Correct 1030 ms 19300 KB Output is correct
13 Correct 209 ms 15852 KB Output is correct
14 Correct 2539 ms 23288 KB Output is correct
15 Correct 2542 ms 23536 KB Output is correct
16 Correct 2756 ms 24752 KB Output is correct
17 Correct 2960 ms 25980 KB Output is correct
18 Correct 2821 ms 25400 KB Output is correct
19 Correct 3002 ms 26364 KB Output is correct
20 Correct 2982 ms 26476 KB Output is correct
21 Correct 3017 ms 26356 KB Output is correct