답안 #306805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306805 2020-09-26T10:03:14 Z MrDomino Furniture (JOI20_furniture) C++14
5 / 100
5000 ms 13944 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2000 + 7;
int n;
int m;
int a[N][N];
bool down[N][N];
bool up[N][N];
bool on[N][N];
int cnt[2 * N];

void init()
{
    for (int i = 1; i <= n + m; i++)
    {
        cnt[i] = 0;
    }
    down[n + 1][m] = 1;
    up[1][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] == 0)
            {
                up[i][j] = up[i - 1][j] | up[i][j - 1];
            }
            else
            {
                up[i][j] = 0;
            }
        }
    }
    for (int i = n; i >= 1; i--)
    {
        for (int j = m; j >= 1; j--)
        {
            if (a[i][j] == 0)
            {
                down[i][j] = down[i + 1][j] | down[i][j + 1];
            }
            else
            {
                down[i][j] = 0;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (up[i][j] && down[i][j])
            {
                cnt[i + j]++;
                on[i][j] = 1;
            }
            else
            {
                on[i][j] = 0;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    ///freopen ("input", "r", stdin);

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
        }
    }
    init();
    int q;
    cin >> q;
    while (q--)
    {
        int r, c;
        cin >> r >> c;
        if (on[r][c] == 0)
        {
            cout << "1\n";
            continue;
        }
        if (cnt[r + c] == 1)
        {
            cout << "0\n";
            continue;
        }
        cout << "1\n";
        a[r][c] = 1;
        init();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1152 KB Output is correct
2 Correct 7 ms 1408 KB Output is correct
3 Correct 49 ms 1280 KB Output is correct
4 Correct 68 ms 1408 KB Output is correct
5 Correct 83 ms 1528 KB Output is correct
6 Correct 151 ms 1408 KB Output is correct
7 Correct 25 ms 1408 KB Output is correct
8 Correct 32 ms 1408 KB Output is correct
9 Correct 32 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1152 KB Output is correct
2 Correct 7 ms 1408 KB Output is correct
3 Correct 49 ms 1280 KB Output is correct
4 Correct 68 ms 1408 KB Output is correct
5 Correct 83 ms 1528 KB Output is correct
6 Correct 151 ms 1408 KB Output is correct
7 Correct 25 ms 1408 KB Output is correct
8 Correct 32 ms 1408 KB Output is correct
9 Correct 32 ms 1408 KB Output is correct
10 Correct 76 ms 1272 KB Output is correct
11 Correct 43 ms 896 KB Output is correct
12 Execution timed out 5081 ms 13944 KB Time limit exceeded
13 Halted 0 ms 0 KB -