답안 #1053699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053699 2024-08-11T15:56:01 Z kachim2 Furniture (JOI20_furniture) C++17
100 / 100
1597 ms 6740 KB
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n, m;
        cin >> n >> m;
        vector<vector<bool>> p(n+2, vector<bool>(m+2, 0));
        vector<vector<bool>> rp(n+2, vector<bool>(m+2, 0));
        vector<vector<int>> inp(n+2, vector<int>(m+2, 0));
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++ ){
            cin >> inp[i][j];
            }
        }
        rp[n][m] = 1;
        p[1][1] = 1;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++ ){
            if(inp[i][j] == 0){
                if(i!=1 || j!=1)
                p[i][j] = p[i-1][j] || p[i][j-1];
     
            }
            }
        }
        for(int i = n; i >0; i--){
            for(int j = m; j >0; j-- ){
            if(inp[i][j] == 0){
     
                if(i!=n || j!=m)
                rp[i][j] = rp[i+1][j] || rp[i][j+1];
            }
            }
        }
        int q;
        cin >> q;
     
     
        for(int _ = 0; _ < q; _++){
            int x, y;
            cin >> x >> y;
            if(p[x][y]){
     
     
     
                bool canwe = 0;
                for(int i = 1; i < x; i++){
                    if(rp[i][y+1] && p[i][y+1])
                    {
                        canwe=1;
                        break;
                    }
                }
                //if(!canwe)
                for(int i = x+1; i <= n; i++){
                    if(rp[i][y-1] && p[i][y-1])
                    {
                        canwe=1;
                        break;
                    }
                }
                if(!canwe){
                    cout << "0\n";
                    continue;
                }
                cout << "1\n";
                p[x][y] = 0;
                stack<pair<int, int>> pos;
                pos.push({x+1, y});
                pos.push({x, y+1});
                while(!pos.empty()){
                    auto v = pos.top();
                    pos.pop();
                    if(p[v.first][v.second]){
                        p[v.first][v.second] = p[v.first-1][v.second] || p[v.first][v.second-1];
                        if(!p[v.first][v.second]){
                            pos.push({v.first+1, v.second});
                            pos.push({v.first, v.second+1});
                        }
                    }
                }
                rp[x][y] = 0;
                stack<pair<int, int>> rpos;
                rpos.push({x-1, y});
                rpos.push({x, y-1});
                while(!rpos.empty()){
                    auto v = rpos.top();
                    rpos.pop();
                    if(rp[v.first][v.second]){
                        rp[v.first][v.second] = rp[v.first+1][v.second] || rp[v.first][v.second+1];
                        if(!rp[v.first][v.second]){
                            rpos.push({v.first-1, v.second});
                            rpos.push({v.first, v.second-1});
                        }
                    }
                }
            }else{
                cout << "1\n";
            }
        }
     
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 9 ms 500 KB Output is correct
5 Correct 10 ms 348 KB Output is correct
6 Correct 12 ms 348 KB Output is correct
7 Correct 12 ms 504 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 12 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 9 ms 500 KB Output is correct
5 Correct 10 ms 348 KB Output is correct
6 Correct 12 ms 348 KB Output is correct
7 Correct 12 ms 504 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 12 ms 348 KB Output is correct
10 Correct 31 ms 720 KB Output is correct
11 Correct 8 ms 348 KB Output is correct
12 Correct 501 ms 4992 KB Output is correct
13 Correct 88 ms 4188 KB Output is correct
14 Correct 1034 ms 5784 KB Output is correct
15 Correct 1078 ms 5608 KB Output is correct
16 Correct 1105 ms 6224 KB Output is correct
17 Correct 1375 ms 6480 KB Output is correct
18 Correct 1284 ms 6228 KB Output is correct
19 Correct 1205 ms 6740 KB Output is correct
20 Correct 1597 ms 6740 KB Output is correct
21 Correct 1521 ms 6736 KB Output is correct