結果

問題 No.697 池の数はいくつか
ユーザー maimai
提出日時 2018-06-09 20:06:41
言語 cLay
(20240714-1)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 2,809 ms
コンパイル使用メモリ 178,292 KB
実行使用メモリ 39,328 KB
最終ジャッジ日時 2024-05-04 05:29:16
合計ジャッジ時間 7,211 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 WA -
testcase_11 RE -
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
6,940 KB
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 AC 27 ms
7,968 KB
testcase_25 AC 28 ms
8,064 KB
testcase_26 AC 27 ms
8,076 KB
testcase_27 AC 27 ms
8,016 KB
testcase_28 AC 27 ms
7,840 KB
testcase_29 AC 190 ms
39,152 KB
testcase_30 AC 222 ms
39,328 KB
testcase_31 AC 197 ms
39,268 KB
testcase_32 AC 223 ms
39,316 KB
testcase_33 AC 229 ms
39,280 KB
testcase_34 AC 230 ms
39,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind {
public:
    vector<int> data;
    Unionfind(size_t size) : data(size, -1) { }
    bool connect(size_t x, size_t y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = (int)x;
        }
        return x != y;
    }
    inline bool same(size_t x, size_t y) {
        return root(x) == root(y);
    }
    inline size_t root(size_t x) {
        return (size_t)(data[x] < 0 ? x : data[x] = root(data[x]));
    }
    inline int size(size_t x) {
        return -data[root(x)];
    }
};

int H,W;
{
    rd(H,W);
    Unionfind uf(H*W+1);
    int p = 0;
    REP(y, H){
        REP(x, W){
            int c;rd(c);
            if (c == 0) uf.connect(p, H*W);
            else{
                if (0<y && !uf.same(p-H, H*W)) uf.connect(p, p-H);
                if (0<x && !uf.same(p-1, H*W)) uf.connect(p, p-1);
            }
            ++p;
        }
    }
    int cnt = 0;
    REP(i, H*W+1) cnt += uf.root(i) == i;
    wt(cnt-1);
}
0