//i_love_aisukiuwu
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/home/trucmai/.vim/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
void open(){
if(fopen("i.inp","r")){
freopen("i.inp","r",stdin);
freopen("o.out","w",stdout);
}
}
#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "
const int MN1 = 1e6 + 5,MN2 = 1e3 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,m; bool c[MN2][MN2];
ll place[MN1];
ll dx[] = {0,0,1,-1},dy[] = {1,-1,0,0};
void bfs(ll x,ll y){
queue<pi>qu; qu.emplace(x,y);
auto check=[&](ll x,ll y)->bool{
if((x == 1 && y == 1) || (x == n && y == m)) return false;
if((x==n || c[x+1][y]) && (y==m || c[x][y+1])) return true;
if((x==1 || c[x-1][y]) && (y==1 || c[x][y-1])) return true;
return false;
};
while(!qu.empty()){
auto [cx,cy]= qu.front(); qu.pop();
c[cx][cy] = true; place[cx + cy]--;
if(min(x,y) <= 0 || x > n || y > m || c[x][y]) continue;
for(ll i = 0;i < 4;++i){
ll nx = cx + dx[i],ny = cy + dy[i];
if(check(nx,ny)) qu.emplace(nx,ny);
}
}
}
void solve(){
cin>>n>>m;
for(ll i = 1;i <= n;++i)
for(ll j = 1;j <= m;++j){
if(c[i][j]){ll tmp; cin>>tmp; continue;}
cin>>c[i][j];
if(c[i][j]) bfs(i,j);
}
ll q; cin>>q;
while(q--){
ll x,y; cin>>x>>y;
if(c[x][y]) cout<<1<<endl;
else if(place[x + y]) cout<<0<<endl;
else{
cout<<1<<endl;
bfs(x,y);
}
}
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
open();
ll t = 1; //cin>>t;
while(t--) solve();
#ifdef LOCAL
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
Compilation message
furniture.cpp: In function 'void open()':
furniture.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen("i.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
furniture.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen("o.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |