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 <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
bool a[201][201];
int r, c, n, x1, y1, x2, y2, x, y;
bool bfs(){
queue<pair<int, int> > q;
q.push(make_pair(x1, y1));
while (!q.empty()){
pair<int, int> f = q.front(); q.pop();
int u = f.first, v = f.second;
if (u == x2 && v == y2){
return true;
}
if (u > x2 || v > y2){
continue;
}
if (a[u][v] && u < r){
q.push(make_pair(u + 1, v));
}
if (v < c){
q.push(make_pair(u, v + 1));
}
}
return false;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>r>>c>>n;
for (int i = 1; i <= r; i++){
for (int j = 1; j <= c; j++){
a[i][j] = false;
}
}
while (n--){
cin>>x>>y;
a[x][y] = true;
}
int t; cin>>t;
while (t--){
cin>>x1>>y1>>x2>>y2;
if (bfs()){
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... |