답안 #573018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573018 2022-06-05T16:13:31 Z urosk Furniture (JOI20_furniture) C++14
0 / 100
2 ms 1108 KB
//https://oj.uz/problem/view/JOI20_furniture
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;

#define maxn 1005
ll n,m;
ll a[maxn][maxn];
bool vis[maxn][maxn];
set<pll> s[2*maxn];
void dfs(ll x,ll y){
    vis[x][y] = 1;
    if(s[x+y].find({x,y})!=s[x+y].end()) s[x+y].erase(s[x+y].find({x,y}));
    if(vis[x+1][y-1]){
        if(!vis[x+1][y]) dfs(x+1,y);
        if(!vis[x][y-1]) dfs(x,y-1);
    }
    if(vis[x-1][y+1]){
        if(!vis[x-1][y]) dfs(x-1,y);
        if(!vis[x][y+1]) dfs(x,y+1);
    }
    return;
}
int main(){
	daj_mi_malo_vremena
    cin >> n >> m;
    for(ll i = 0;i<=n+1;i++) for(ll j = 0;j<=m+1;j++) vis[i][j] = 1;
    for(ll i = 1;i<=n;i++){
        for(ll j = 1;j<=m;j++){
            cin >> a[i][j];
            if(a[i][j]==0){
                s[i+j].insert({i,j});
                vis[i][j] = 0;
            }
        }
    }
    for(ll i = 1;i<=n;i++){
        for(ll j = 1;j<=m;j++){
            if(i+j==2||i+j==n+m) continue;
            if(!vis[i][j]&&((vis[i-1][j]&&vis[i][j-1])||(vis[i+1][j]&&vis[i][j+1]))) dfs(i,j);
        }
    }
    ll q; cin >> q;
    while(q--){
        //here;
        ll x,y; cin >> x>> y;
        //for(ll i = 0;i<=n;i++) ceri(vis[i],0,m);
        if(vis[x][y]||sz(s[x+y])==1) cout<<0<<endl;
        else{
            cout<<1<<endl;
            dfs(x,y);
        }
    }
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -