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>
#define DIM 1010
using namespace std;
int a[DIM][DIM];
deque <pair<int,int> > c,w;
int n,m,i,j,q,x,y;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
cin>>a[i][j];
for (i=0;i<=m+1;i++)
a[0][i] = a[n+1][i] = 1;
for (i=1;i<=n;i++)
a[i][0] = a[i][m+1] = 1;
cin>>q;
for (;q--;){
cin>>x>>y;
c.clear(), w.clear();
c.push_back(make_pair(x,y));
w.push_back(make_pair(x,y));
a[x][y] = 1;
int ok = 1;
while (!c.empty()){
int i = c.front().first;
int j = c.front().second;
c.pop_front();
if (i == n && j == m){
ok = 0;
break;
}
if (!a[i][j+1] && a[i-1][j+1]){
c.push_back(make_pair(i,j+1));
w.push_back(make_pair(i,j+1));
a[i][j+1] = 1;
}
if (!a[i+1][j] && a[i+1][j-1]){
c.push_back(make_pair(i+1,j));
w.push_back(make_pair(i+1,j));
a[i+1][j] = 1;
}
}
cout<<ok<<"\n";
if (!ok){
/// trb sa demarchez
for (auto it : w)
a[it.first][it.second] = 0;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |