Submission #470970

# Submission time Handle Problem Language Result Execution time Memory
470970 2021-09-06T13:28:51 Z iulia13 Furniture (JOI20_furniture) C++14
0 / 100
296 ms 524292 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 1005;
int n, m;
int a[N][N];
int SePoate[N][N];
int diag[N + N];
int b = 1;
struct ura{
    int x, y;
};
int dL[4] = {0, 1, 0, -1};
int dC[4] = {1, 0, -1, 0};
int verif(int x, int y)
{
    if (x < 1 || y < 1 || n < x || m < y)
        return 1;
    return 0;
}
void lee(int xs, int ys, int l, int r)
{
    queue <ura> q;
    SePoate[xs][ys] += b;
    q.push({xs, ys});
    while (!q.empty())
    {
        int x = q.front().x;
        int y = q.front().y;
        q.pop();
        for (int i = l; i <= r; i++)
        {
            int xx = x + dL[i];
            int yy = y + dC[i];
            if (verif(xx, yy) || a[xx][yy])
                continue;
            if (SePoate[xx][yy] < b)
            {
                SePoate[xx][yy] += b;
                q.push({xx, yy});
            }
        }
    }

}
void upd(int x, int y)
{
    if (verif(x, y)  && !SePoate[x][y])
        return;

    SePoate[x][y] = 0;
    diag[x + y]--;
    if (verif(x - 1, y + 1) || !SePoate[x - 1][y + 1])
    {
        upd(x, y + 1);
        upd(x - 1, y);
    }
    if (verif(x + 1, y - 1) || !SePoate[x + 1][y - 1])
    {
        upd(x, y - 1);
        upd(x + 1, y);
    }
}
int main()
{
    int i, j;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
            SePoate[i][j] = 1;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            diag[i + j]++;
            if (a[i][j])
                upd(i, j);
        }
    int q;
    cin >> q;
    while(q--)
    {
        int x, y;
        cin >> x >> y;
        if (SePoate[x][y] == 0)
        {
            cout << 1 << '\n';
            continue;
        }
        if (diag[x + y] > 1)
        {
            cout << 1 << '\n';
            upd(x, y);
            continue;
        }
        cout << 0 << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 296 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 296 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -