Submission #1213006

#TimeUsernameProblemLanguageResultExecution timeMemory
1213006cpdreamerFurniture (JOI20_furniture)C++20
0 / 100
5093 ms580 KiB
#include <bits/stdc++.h>
using namespace std;
const long long  INF = 1e12;
typedef long long ll;
const ll MOD=(ll) 998244353;
#define P pair
#define S second
#define F first
#define pb push_back
#define V vector
#define all(v) v.begin(),v.end()
void file() {
    freopen("input.txt.txt", "r", stdin);
    freopen("output.txt.txt", "w", stdout);
}
bool gridt[(int)1001][(int)1001];
bool gridb[(int)1001][(int)1001];
P<int,int> top[(int)2002],bot[2002];
bool f=false;
void rem_t(P<int,int>p,P<int,int>c) {
    if (!gridt[p.F][p.S] && p.F+p.S>=c.F+c.S  && top[p.F+p.S].F==p.F && top[p.F+p.S].S==p.S) {
        f=true;
    }
    if (f) {
        return;
    }
    top[p.F+p.S]=p;
    if (!gridt[p.F][p.S+1]) {
        rem_t({p.F,p.S+1},c);
    }
    if (f) {
        return;
    }
    if (!gridt[p.F+1][p.S]) {
        rem_t({p.F+1,p.S},c);
    }
    if (f) {
        return;
    }
    gridt[p.F][p.S]=true;
    rem_t(top[p.F+p.S-1],c);
}
void rem_b(P<int,int>p,P<int,int>c) {
    if (!gridb[p.F][p.S] && p.F+p.S>=c.F+c.S && bot[p.F+p.S].F==p.F && bot[p.F+p.S].S==p.S) {
        f=true;
    }
    if (f) {
        return;
    }
    bot[p.F+p.S]=p;
    if (!gridb[p.F+1][p.S]) {
        rem_b({p.F+1,p.S},c);
    }
    if (f) {
        return;
    }
    if (!gridb[p.F][p.S+1]) {
        rem_b({p.F,p.S+1},c);
    }
    if (f) {
        return ;
    }
    gridb[p.F][p.S]=true;
    rem_b(bot[p.F+p.S-1],c);
}
void solve(){
    int n,m;
    cin>>n>>m;
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            int x;
            cin>>x;
            gridt[i][j]=x;
            gridb[i][j]=x;
        }
    }
    for (int i=0;i<=n;i++) {
        gridt[i][m]=true;
        gridb[i][m]=true;
    }
    for (int i=0;i<=m;i++) {
        gridt[n][i]=true;
        gridb[n][i]=true;
    }
    for (int i=0;i<n;i++) {
        top[m-1+i]={i,m-1};
        bot[i]={i,0};
    }
    for (int i=0;i<m;i++) {
        top[i]={0,i};
        bot[n-1+i]={n-1,i};
    }
    for (int i=0;i<n;i++) {
        for (int j=0;j<m;j++) {
            if (gridt[i][j]) {
                if (top[i+j].F==i && top[i+j].S==j) {
                    f=false;
                    rem_t({top[i+j-1].F,top[i+j-1].S},{i,j});
                }
            }
            if (gridb[i][j]) {
                if (bot[i+j].F==i && bot[i+j].S==j) {
                    f=false;
                    rem_b({bot[i+j-1].F,bot[i+j-1].S},{i,j});
                }
            }
        }
    }
    int q;
    cin>>q;
    while (q--) {
        int x,y;
        cin>>x>>y;
        x--,y--;
        if (top[x+y].F==x && top[x+y].S==y && bot[x+y].F==x && bot[x+y].S==y) {
            cout<<0<<endl;
            continue;
        }
        cout<<1<<endl;
        gridt[x][y]=true;
        gridb[x][y]=true;
        if (top[x+y].F==x && top[x+y].S==y) {
            f=false;
            rem_t({top[x+y-1].F,top[x+y-1].S},{x,y});
        }
        if (bot[x+y].F==x && bot[x+y].S==y) {
            f=false;
            rem_b({bot[x+y-1].F,bot[x+y-1].S},{x,y});
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //file();
    solve();
    return 0;
}

Compilation message (stderr)

furniture.cpp: In function 'void file()':
furniture.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("input.txt.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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("output.txt.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...