Submission
Status:
---P--PP
Score: 39
User: .n0t_gloomy.
Problemset: อพยพ
Language: cpp
Time: 0.003 second
Submitted On: 2025-03-06 19:12:55
#include <bits/stdc++.h>
using namespace std;
int H,W,tc;
void printVecString(vector<string> s)
{
for (auto it : s)
{
cout<<it<<"\n";
}
cout<<"\n";
return;
}
bool fly(int a, int b, int c, int d, int minHeight, int maxHeight,vector<string> &mp)
{
//cout<<"you enter the freaking function\n";
if (a == c && b == d)
{
return true;
}
//cout<<"passed the 1st case\n";
if (a < 0 || a >= H || b < 0 || b >= W)
{
return false;
}
//cout<<"passed the 2nd case\n";
if (a < minHeight || a > maxHeight)
{
return false;
}
//cout<<"passed the 3rd case\n";
if (mp[a][b] == '#')
{
return false;
}
//cout<<"passed the passed all case\n";
mp[a][b] = '#';
//cout<<"\nchecked "<<a<<" "<<b<<"\n";
//printVecString(mp);
return fly(a+1,b,c,d,minHeight,maxHeight,mp) || fly(a-1,b,c,d,minHeight,maxHeight,mp) || fly(a,b+1,c,d,minHeight,maxHeight,mp) || fly(a,b-1,c,d,minHeight,maxHeight,mp);
}
int main()
{
cin>>H>>W>>tc;
vector<string> mp;
for (int i = 0; i < H; i++)
{
string temp;
cin>>temp;
mp.push_back(temp);
}
vector<string> original = mp;
while (tc--)
{
int a,b,c,d,l;
cin>>a>>b>>c>>d>>l;
a--; b--; c--; d--;
int maxHeight, minHeight;
maxHeight = a + l;
minHeight = a-l;
if (fly(a,b,c,d,minHeight,maxHeight,mp))
{
cout<<"1\n";
}
else
{
cout<<"0\n";
}
mp = original;
}
return 0;
}
/*
6 10 1
##......##
##.####.##
#....##...
#.##....##
..####.###
##...#...#
5 1 3 10 10
*/