Submission

Status:

PPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: 9drxwz

Problemset: อพยพ

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-05 12:48:03

#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    int m,n,animal;
    cin>>m>>n>>animal;
    vector<vector<char>> mp(m+1,vector<char>(n+1));
    for(int i=1;i<=m;i++){
        string x;
        cin>>x;
        for(int j=1;j<=n;j++){
            mp[i][j]=x[j-1];
        }
    }
    for(int i=0;i<animal;i++){
        int a,b,c,d,l;
        cin>>a>>b>>c>>d>>l;
        stack<pair<int,int>> dfs;
        dfs.push({a,b});
        vector<vector<char>> cmp=mp;
        cmp[a][b]='#';
        bool found=false;
        while(!dfs.empty()){
            int x = dfs.top().first;
            int y = dfs.top().second;
            dfs.pop();
            if(x+1<=a+l && x+1<=m && cmp[x+1][y]=='.'){
                dfs.push({x+1,y});
                cmp[x+1][y]='#';
            }
            if(x-1>=a-l && x-1>=1 && cmp[x-1][y]=='.'){
                dfs.push({x-1,y});
                cmp[x-1][y]='#';
            }
            if(y+1<=n && cmp[x][y+1]=='.'){
                dfs.push({x,y+1});
                cmp[x][y+1]='#';
            }
            if(y-1>=1 && cmp[x][y-1]=='.'){
                dfs.push({x,y-1});
                cmp[x][y-1]='#';
            }
            if(x==c && y==d){
                found=true;
            }
        }
        if(found){
            cout<<1<<'\n';
        }else{
            cout<<0<<'\n';
        }
    }
}