結果

問題 No.1605 Matrix Shape
ユーザー sten_sansten_san
提出日時 2021-07-16 23:01:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,141 bytes
コンパイル時間 2,911 ms
コンパイル使用メモリ 208,348 KB
実行使用メモリ 28,984 KB
最終ジャッジ日時 2023-09-20 15:27:09
合計ジャッジ時間 6,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
14,600 KB
testcase_01 AC 10 ms
14,784 KB
testcase_02 AC 9 ms
14,724 KB
testcase_03 WA -
testcase_04 AC 9 ms
14,796 KB
testcase_05 AC 10 ms
14,744 KB
testcase_06 WA -
testcase_07 AC 10 ms
14,924 KB
testcase_08 WA -
testcase_09 AC 10 ms
14,780 KB
testcase_10 AC 10 ms
14,596 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 10 ms
14,748 KB
testcase_14 AC 11 ms
14,732 KB
testcase_15 AC 9 ms
14,820 KB
testcase_16 AC 11 ms
14,736 KB
testcase_17 AC 10 ms
14,732 KB
testcase_18 AC 10 ms
14,732 KB
testcase_19 AC 165 ms
28,732 KB
testcase_20 WA -
testcase_21 AC 119 ms
22,520 KB
testcase_22 AC 159 ms
28,660 KB
testcase_23 WA -
testcase_24 AC 161 ms
28,892 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 47 ms
18,384 KB
testcase_28 AC 44 ms
18,372 KB
testcase_29 AC 46 ms
18,368 KB
testcase_30 WA -
testcase_31 AC 107 ms
22,644 KB
testcase_32 WA -
testcase_33 AC 87 ms
20,608 KB
testcase_34 WA -
testcase_35 AC 104 ms
26,024 KB
testcase_36 AC 56 ms
21,788 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 0;
    }

    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