結果

問題 No.1605 Matrix Shape
ユーザー sten_sansten_san
提出日時 2021-07-16 22:56:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,924 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 208,184 KB
実行使用メモリ 18,092 KB
最終ジャッジ日時 2023-09-20 15:22:16
合計ジャッジ時間 5,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
10,052 KB
testcase_01 AC 8 ms
10,120 KB
testcase_02 AC 6 ms
9,996 KB
testcase_03 WA -
testcase_04 AC 7 ms
10,028 KB
testcase_05 AC 8 ms
10,072 KB
testcase_06 WA -
testcase_07 AC 6 ms
10,064 KB
testcase_08 WA -
testcase_09 AC 8 ms
10,024 KB
testcase_10 AC 8 ms
9,956 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 8 ms
10,128 KB
testcase_14 AC 7 ms
10,096 KB
testcase_15 AC 8 ms
9,980 KB
testcase_16 AC 7 ms
9,960 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 106 ms
17,984 KB
testcase_20 WA -
testcase_21 AC 81 ms
14,688 KB
testcase_22 AC 94 ms
18,092 KB
testcase_23 WA -
testcase_24 AC 101 ms
17,976 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 42 ms
12,836 KB
testcase_28 AC 40 ms
12,632 KB
testcase_29 AC 43 ms
12,616 KB
testcase_30 WA -
testcase_31 AC 82 ms
14,644 KB
testcase_32 WA -
testcase_33 AC 69 ms
13,796 KB
testcase_34 WA -
testcase_35 AC 76 ms
16,412 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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 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]);
    }

    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;
    }

    cout << 1 << endl;
}

0