답안 #1053700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053700 2024-08-11T15:56:57 Z kachim2 Furniture (JOI20_furniture) C++17
100 / 100
1761 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;
                        
                    }
                }
                if(!canwe)
                for(int i = x+1; i <= n; i++){
                    if(rp[i][y-1] && p[i][y-1])
                    {
                        canwe=1;
                        
                    }
                }
                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 2 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 5 ms 396 KB Output is correct
4 Correct 9 ms 348 KB Output is correct
5 Correct 10 ms 500 KB Output is correct
6 Correct 14 ms 492 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 12 ms 500 KB Output is correct
9 Correct 12 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 5 ms 396 KB Output is correct
4 Correct 9 ms 348 KB Output is correct
5 Correct 10 ms 500 KB Output is correct
6 Correct 14 ms 492 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 12 ms 500 KB Output is correct
9 Correct 12 ms 344 KB Output is correct
10 Correct 36 ms 604 KB Output is correct
11 Correct 8 ms 344 KB Output is correct
12 Correct 661 ms 4952 KB Output is correct
13 Correct 92 ms 4184 KB Output is correct
14 Correct 1174 ms 5808 KB Output is correct
15 Correct 1234 ms 5716 KB Output is correct
16 Correct 1077 ms 6228 KB Output is correct
17 Correct 1396 ms 6480 KB Output is correct
18 Correct 1325 ms 6224 KB Output is correct
19 Correct 1219 ms 6740 KB Output is correct
20 Correct 1761 ms 6736 KB Output is correct
21 Correct 1537 ms 6740 KB Output is correct