| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1344385 | kokokai | Furniture (JOI20_furniture) | C++20 | 177 ms | 10308 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define task "text"
const int N = 1005;
int C[N][N],active[N][N];
int d[N+N];
int n,m,q;
const int dx[] = {-1,0,0,1};
const int dy[] = {0,-1,1,0};
bool check(int x,int y){
if(x<1 || x>n || y<1 || y>m) return 0;
return 1;
}
bool blocked(int x,int y){
if(x == 1 && y == 1) return 0;
if(x == n && y == m) return 0;
if(!active[x-1][y] && !active[x][y-1]) return 1;
if(!active[x+1][y] && !active[x][y+1]) return 1;
return 0;
}
void bfs(int sx,int sy){
if(!active[sx][sy]) return;
queue<pair<int,int>> q;
q.push({sx,sy});
while(!q.empty()){
int x=q.front().fi,y=q.front().se;
//cerr<<x<<' '<<y<<'\n';
q.pop();
active[x][y]=0;
d[x+y]--;
for(int dir=0;dir<4;dir++){
int nx=x+dx[dir];
int ny=y+dy[dir];
if(!check(nx,ny) || !active[nx][ny]) continue;
if(blocked(nx,ny)){
active[x][y]=0;
q.push({nx,ny});
}
}
}
}
int main() {
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
}
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
active[i][j]=1;
d[i+j]++;
}
}
//cout<<d[2+2]<<'\n';
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>C[i][j];
if(C[i][j]) bfs(i,j);
}
}
cin>>q;
while(q--){
int x,y;
cin>>x>>y;
if(!active[x][y]){
cout<<1<<'\n';
}else if(d[x+y] == 1){
cout<<0<<'\n';
}else{
cout<<1<<'\n';
bfs(x,y);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
