제출 #1355773

#제출 시각아이디문제언어결과실행 시간메모리
1355773free_de_la_zenithFurniture (JOI20_furniture)C++20
5 / 100
75 ms12580 KiB
/**
 *    author:  MINHTPC
 *
**/
#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin() , a.end()
#define FOR(i ,a , b) for(int i = a ; i <= b ; ++i)
#define bit(mask,i) ((mask>>i)&1)
#define name "task"
#define lo lower_bound
#define up upper_bound
#define count_bit1(x) __builtin_popcountll(x)
#define count_bit01(x) __builtin_clzll(x)
#define count_bit10(x) __builtin_ctzll(x)

using namespace std;
const int N=1e3+5;
int a[N][N],goods[N][N],R[N][N];
using pii=pair<int,int>;
int n,m;

int dx[5] = {1,-1,0,0};

int dy[5] = {0,0,1,-1};

int lnx[5] = {1,-1,-1,1};

int lny[5] = {-1,1,1,-1};
bool check(int x,int y) {
    return x>=1 && x<=n && y>=1 && y<=m;
}
int cnt[N],tmp[N][N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    if(fopen("umnik.inp","r")) {
        freopen("umnik.inp","r",stdin);
    }
    cin >> n >> m;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) cin >> a[i][j];
    }
    tmp[1][1]=1;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            int up=tmp[i-1][j]|tmp[i][j-1];
            if(a[i][j]==0) tmp[i][j]+=up;
            R[i][j]+=tmp[i][j];
        }
    }
    memset(tmp,0,sizeof tmp);
    tmp[n][m]=1;
    for(int i=n;i>=1;i--) {
        for(int j=m;j>=1;j--) {
            int up=tmp[i+1][j]|tmp[i][j+1];
            if(a[i][j]==0) tmp[i][j]+=up;
            R[i][j]+=tmp[i][j];
        }
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if(R[i][j]>=2) R[i][j]=0;
            else R[i][j]=1;
            if(!R[i][j]) cnt[i+j]++;
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int x,y;
        cin >> x >> y;
        if(R[x][y]==0 && cnt[x+y]==1) {
            cout << 0 << '\n';
        }
        else {
            cout << 1 << '\n';
            queue<pii>q;
            q.push({x,y});
            while(!q.empty()) {
                auto cur=q.front();q.pop();
                int cx=cur.fi,cy=cur.se;
                if(R[cx][cy]) continue;
                R[cx][cy]=1;
                cnt[cx+cy]--;
                for(int i=0;i<4;i++) {
                    int nx=cx+dx[i],ny=cy+dy[i];
                    int ox=cx+lnx[i],oy=cy+lny[i];
                    if(!check(nx,ny)) continue;
                    if(R[nx][ny]) continue;
                    else {
                        if(!check(ox,oy)) q.push({nx,ny});
                        else if(R[ox][oy]) q.push({nx,ny});
                    }
                }
            }
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

furniture.cpp: In function 'int main()':
furniture.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("umnik.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...