답안 #358529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
358529 2021-01-25T17:06:17 Z BartolM Furniture (JOI20_furniture) C++17
5 / 100
390 ms 17388 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=1005;

int n, m, q;
int mat[N][N];
int dp[N][N], cnt[N];
int dx[4]={-1, 0, 1, 0};
int dy[4]={0, 1, 0, -1};
queue <pii> Q;

int ok(int x, int y) {
    if (x<=0 || y<=0 || x>n || y>m) return 0;
    if (!dp[x][y]) return 0;
    return (!dp[x-1][y] && !dp[x][y-1]) || (!dp[x+1][y] && !dp[x][y+1]);
}

void bfs(int x, int y) {
    Q.push(mp(x, y));
    while (!Q.empty()) {
        pii pp=Q.front();
        Q.pop();
        for (int i=0; i<4; ++i) {
            int nx=pp.X+dx[i], ny=pp.Y+dy[i];
            if (!ok(nx, ny)) continue;
            Q.push(mp(nx, ny));
            dp[nx][ny]=0;
            cnt[nx+ny]--;
        }
    }
}

void ispis() {
    printf("-----------------------\n");
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            printf("%d ", dp[i][j]);
        }
        printf("\n");
    }
    printf("----------------------------\n");
}

void solve() {
    dp[0][1]=1;
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            dp[i][j]=(dp[i-1][j] || dp[i][j-1]) && mat[i][j];
        }
    }
    dp[n+1][m]=1;
    for (int i=n; i>=1; --i) {
        for (int j=m; j>=1; --j) {
            dp[i][j]&=dp[i+1][j] || dp[i][j+1];
            cnt[i+j]+=dp[i][j];
        }
    }

    while (q--) {
        int x, y;
        scanf("%d %d", &x, &y);
//        ispis();
        if (!dp[x][y]) {
            printf("1\n");
            continue;
        }
        cnt[x+y]--;
        if (!cnt[x+y]) {
            cnt[x+y]++;
            printf("0\n");
            continue;
        }
        printf("1\n");
        dp[x][y]=0; mat[x][y]=0;
        bfs(x, y);
    }
}

void load() {
    scanf("%d %d", &n, &m);
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            scanf("%d", &mat[i][j]);
            mat[i][j]^=1;
        }
    }
    scanf("%d", &q);
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

furniture.cpp: In function 'void solve()':
furniture.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp: In function 'void load()':
furniture.cpp:93:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   93 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:96:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   96 |             scanf("%d", &mat[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
furniture.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  100 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 3 ms 1004 KB Output is correct
4 Correct 4 ms 1132 KB Output is correct
5 Correct 4 ms 1132 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 5 ms 1132 KB Output is correct
8 Correct 4 ms 1132 KB Output is correct
9 Correct 5 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 3 ms 1004 KB Output is correct
4 Correct 4 ms 1132 KB Output is correct
5 Correct 4 ms 1132 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 5 ms 1132 KB Output is correct
8 Correct 4 ms 1132 KB Output is correct
9 Correct 5 ms 1132 KB Output is correct
10 Correct 13 ms 876 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 261 ms 10716 KB Output is correct
13 Correct 106 ms 9728 KB Output is correct
14 Incorrect 390 ms 17388 KB Output isn't correct
15 Halted 0 ms 0 KB -