Submission #573016

# Submission time Handle Problem Language Result Execution time Memory
573016 2022-06-05T16:08:02 Z urosk Furniture (JOI20_furniture) C++14
0 / 100
3 ms 2260 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;
    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
    for(ll i = 0;i<=n;i++) for(ll j = 1;j<=m;j++) vis[i][j] = 1;
    cin >> n >> m;
    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(!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--){
        ll x,y; cin >> x>> y;
        if(sz(s[x+y])==1) cout<<0<<endl;
        else{
            cout<<1<<endl;
            dfs(x,y);
        }
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2260 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2260 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -