Submission #886323

#TimeUsernameProblemLanguageResultExecution timeMemory
886323stefanneaguFurniture (JOI20_furniture)C++17
5 / 100
5090 ms4408 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e3 + 1; bool f[nmax][nmax], mat[nmax][nmax]; int n, m; bool in(int a, int b) { if(min(a, b) < 1 || a > n || b > m) { return 0; } return 1; } void dfs(int i, int j) { if(in(i + 1, j) && !f[i + 1][j] && mat[i + 1][j] == 0) { f[i + 1][j] = 1; dfs(i + 1, j); } if(in(i, j + 1) && !f[i][j + 1] && mat[i][j + 1] == 0) { f[i][j + 1] = 1; dfs(i, j + 1); } } int main() { cin >> n >> m; for(int i = 1; i <= n; i ++) { for(int j = 1; j <= m; j ++) { cin >> mat[i][j]; } } int q; cin >> q; for(int i = 1; i <= q; i ++) { int a, b; cin >> a >> b; mat[a][b] = 1; for(int x = 1; x <= n; x ++) { for(int j = 1; j <= m; j ++) { f[x][j] = 0; } } f[1][1] = 1; dfs(1, 1); if(!f[n][m]) { cout << "0\n"; mat[a][b] = 0; } else { cout << "1\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...