Submission #704623

#TimeUsernameProblemLanguageResultExecution timeMemory
704623Abrar_Al_SamitFurniture (JOI20_furniture)C++17
0 / 100
142 ms348 KiB
#include<bits/stdc++.h> using namespace std; int dx[] {1, -1, 0, 0}; int dy[] {0, 0, 1, -1}; void PlayGround() { int n, m; cin>>n>>m; int a[n+1][m+1]; bool vis[n+1][m+1]; for(int i=1; i<=n; ++i) { for(int j=1; j<=m; ++j) { cin>>a[i][j]; } } auto valid = [&] (int x, int y) { return min(x, y)>=1 && x<=n && y<=m; }; int q; cin>>q; while(q--) { int x, y; cin>>x>>y; a[x][y] = 1; memset(vis, 0, sizeof vis); queue<pair<int,int>>q; q.emplace(1, 1); while(!q.empty()) { auto [x, y] = q.front(); q.pop(); if(vis[x][y]) continue; vis[x][y] = true; for(int k=0; k<4; ++k) { int nx = x + dx[k], ny = y + dy[k]; if(valid(nx, ny) && a[nx][ny]==0) { q.emplace(nx, ny); } } } if(!vis[n][m]) { cout<<"0\n"; a[x][y] = 0; } else { cout<<"1\n"; } } // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...