Submission #516473

#TimeUsernameProblemLanguageResultExecution timeMemory
516473terrasphereFurniture (JOI20_furniture)C++17
5 / 100
5019 ms7212 KiB
#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)

furniture.cpp: In function 'int main()':
furniture.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
furniture.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d",&arr[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
furniture.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...