This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
typedef long long ll;
void dfs(vector<vector<bool>>&a,vector<vector<vector<int>>>&b,int x,int y,int &n, int &m)
{
if(b[x][y][x]<m+1)
{
return;
}
b[x][y][x]=y;
if(a[x][y] && x<n-1)
{
dfs(a,b,x+1,y,n,m);
for(int w=x+1;w<n;w++)
{
b[x][y][w]=b[x+1][y][w];
}
}
if(y<m-1)
{
dfs(a,b,x,y+1,n,m);
if(!a[x][y])
{
for(int w=x+1;w<n;w++)
{
b[x][y][w]=b[x][y+1][w];
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m,g,q;
cin>>n>>m>>g;
vector<vector<bool>>a(n,vector<bool>(m));
for(int i=0;i<g;i++)
{
int x,y;
cin>>x>>y;
a[x-1][y-1]=true;
}
vector<vector<vector<int>>>b(n,vector<vector<int>>(m,vector<int>(n,m+1)));
for(int i=0;i<n;i++)
{
dfs(a,b,i,0,n,m);
}
cin>>q;
// for(int i=0;i<n;i++)
// {
/// cout<<b[1][1][i]<<endl;
////}
while(q--)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--;x2--;
y1--;y2--;
if(b[x1][y1][x2]<=y2)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |