답안 #998741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
998741 2024-06-14T15:40:35 Z cpptowin Furniture (JOI20_furniture) C++17
0 / 100
2 ms 2648 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
struct DSU
{
    vi par, sz;
    DSU(int n) : par(n), sz(n){};
    void make(int u)
    {
        par[u] = u;
        sz[u] = 1;
    }
    int find(int u)
    {
        return u == par[u] ? u : par[u] = find(par[u]);
    }
    void Union(int u, int v)
    {
        u = find(u);
        v = find(v);
        if (u == v)
            return;
        if (sz[u] < sz[v])
            swap(u, v);
        sz[u] += sz[v];
        par[v] = u;
    }
};
int n, m, q, c[N][N];
int id(int i, int j)
{
    return (i - 1) * m + j;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int lx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int ly[] = {1, -1, 0, 0, -1, 1, -1, 1};
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    fo(i, 1, n) fo(j, 1, m) cin >> c[i][j];
    DSU g(n * m + 9);
    fo(i, 1, n * m + 4) g.make(i);
    fo(i, 1, n) fo(j, 1, m) if (c[i][j] == 1)
    {
        if (i == 1)
            g.Union(id(i, j), n * m + 1);
        if (i == n)
            g.Union(id(i, j), n * m + 3);
        if (j == 1)
            g.Union(id(i, j), n * m + 2);
        if (j == m)
            g.Union(id(i, j), n * m + 4);
        fo(k, 0, 3)
        {
            int i1 = i + dx[k];
            int j1 = j + dy[k];
            if (c[i][j] == 1 and c[i1][j1] == 1)
                g.Union(id(i, j), id(i1, j1));
        }
    }
    cin >> q;
    while (q--)
    {
        int i, j;
        cin >> i >> j;
        vii save;
        int ok[4] = {};
        if (i == 1)
            ok[0] = 1;
        if (i == n)
            ok[2] = 1;
        if (j == 1)
            ok[1] = 1;
        if (j == m)
            ok[3] = 1;
        fo(k, 0, 7)
        {
            int i1 = i + lx[k];
            int j1 = j + ly[k];
            if (c[i1][j1] == 1)
            {
                fo(x, 1, 4)
                {
                    if (g.find(n * m + x) == g.find(id(i1, j1)))
                        ok[x - 1] = 1;
                }
            }
        }
        if (ok[0] + ok[1] == 2 or ok[0] + ok[2] == 2 or ok[1] + ok[3] == 2 or ok[2] + ok[3] == 2)
            cout << 0;
        else
        {
            if (i == 1)
                g.Union(id(i, j), n * m + 1);
            if (i == n)
                g.Union(id(i, j), n * m + 3);
            if (j == 1)
                g.Union(id(i, j), n * m + 2);
            if (j == m)
                g.Union(id(i, j), n * m + 4);
            cout << 1;
            c[i][j] = 1;
            fo(k, 0, 3)
            {
                int i1 = i + dx[k];
                int j1 = j + dy[k];
                if (c[i][j] == 1 and c[i1][j1] == 1)
                    g.Union(id(i, j), id(i1, j1));
            }
        }
        en;
    }
}

Compilation message

furniture.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   77 | main()
      | ^~~~
furniture.cpp: In function 'int main()':
furniture.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 2 ms 2648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 2 ms 2648 KB Output isn't correct
3 Halted 0 ms 0 KB -