# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516473 | terrasphere | Furniture (JOI20_furniture) | C++17 | 5019 ms | 7212 KiB |
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;
int arr[1111][1111];
int n,m;
bool visited[1111][1111];
queue<pair<int,int>> que;
bool possible()
{
memset(visited,false,sizeof(visited));
que.push({1,1});
while(!que.empty())
{
pair<int,int> c;
c=que.front();
que.pop();
if(c.first==n && c.second==m)
return true;
if(c.second+1<=m && arr[c.first][c.second+1]==0 && !visited[c.first][c.second+1])
{
que.push({c.first,c.second+1});
visited[c.first][c.second+1]=true;
}
if(c.first+1<=n && arr[c.first+1][c.second]==0 && !visited[c.first+1][c.second])
{
que.push({c.first+1,c.second});
visited[c.first+1][c.second]=true;
}
}
return false;
}
int main()
{
int q;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&arr[i][j]);
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
int a,b;
scanf("%d%d",&a,&b);
if(arr[a][b]==1)
{
printf("0\n");
continue;
}
arr[a][b]=1;
if(possible())
printf("1\n");
else
{
printf("0\n");
arr[a][b]=0;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |