結果

問題 No.1605 Matrix Shape
ユーザー sten_sansten_san
提出日時 2021-07-16 23:07:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,143 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 210,020 KB
実行使用メモリ 28,996 KB
最終ジャッジ日時 2023-09-20 15:34:01
合計ジャッジ時間 6,477 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
14,760 KB
testcase_01 RE -
testcase_02 AC 10 ms
14,672 KB
testcase_03 RE -
testcase_04 AC 11 ms
14,680 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 11 ms
14,788 KB
testcase_08 RE -
testcase_09 AC 12 ms
14,656 KB
testcase_10 AC 11 ms
14,800 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 AC 11 ms
14,792 KB
testcase_14 AC 12 ms
14,592 KB
testcase_15 AC 11 ms
14,592 KB
testcase_16 AC 11 ms
14,924 KB
testcase_17 AC 11 ms
14,600 KB
testcase_18 AC 11 ms
14,796 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 142 ms
22,720 KB
testcase_22 AC 171 ms
28,744 KB
testcase_23 RE -
testcase_24 AC 179 ms
28,752 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 49 ms
18,416 KB
testcase_28 AC 46 ms
18,420 KB
testcase_29 AC 48 ms
18,432 KB
testcase_30 RE -
testcase_31 AC 137 ms
22,672 KB
testcase_32 RE -
testcase_33 AC 108 ms
20,528 KB
testcase_34 RE -
testcase_35 AC 128 ms
26,200 KB
testcase_36 AC 70 ms
21,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

#include <atcoder/dsu>

int main() {
    constexpr int lim = 200000;

    int n; cin >> n;

    auto g = vec<int>(uns, lim, 0);
    auto r = vec<int>(uns, lim, 0);
    auto h = vec<int>(uns, n);
    auto w = vec<int>(uns, n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i] >> w[i]; --h[i]; --w[i];
        g[h[i]].push_back(w[i]);
        r[w[i]].push_back(h[i]);
    }

    atcoder::dsu dsu(lim);
    auto in = vec<int>(0, lim);
    auto out = vec<int>(0, lim);
    for (int i = 0; i < lim; ++i) {
        for (auto v : g[i]) {
            ++out[i]; --out[v];
            ++in[v]; --in[i];
            dsu.merge(i, v);
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!dsu.same(h[0], h[i]) || !dsu.same(w[0], w[i])) {
            cout << 0 << endl;
            return 0;
        }
    }

    if (count(begin(out), end(out), 0) == lim) {
        int ans = 0;

        for (int i = 0; i < lim; ++i) {
            ans += size(g[i]);
        }

        //cout << ans << endl;
        return 1;
    }

    if (1 < count(begin(in), end(in), 1) || 1 < count(begin(out), end(out), 1)) {
        cout << 0 << endl;
        return 0;
    }

    if (count(begin(in), end(in), 0) != lim - 2 || count(begin(out), end(out), 0) != lim - 2) {
        cout << 0 << endl;
        return 0;
    }

    cout << 1 << endl;
}

0