結果

問題 No.3009 Union-Find でつながろう!
ユーザー KumaTachiRen
提出日時 2025-01-17 22:48:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,551 bytes
コンパイル時間 6,780 ms
コンパイル使用メモリ 334,336 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-17 22:48:12
合計ジャッジ時間 9,862 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/all>
using namespace atcoder;

using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vm>;
inline ostream &operator<<(ostream &os, const mint x)
{
    return os << x.val();
};
inline istream &operator>>(istream &is, mint &x)
{
    long long v;
    is >> v;
    x = v;
    return is;
};

struct Fast
{
    Fast()
    {
        std::cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(10);
    }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--)
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

void solve()
{
    int m, n;
    cin >> m >> n;

    using bs = bitset<4096>;
    vector<bs> b(m);
    vector<bool> f(n);
    rep(i, 0, m)
    {
        string s;
        cin >> s;
        b[i] = bs(s);
        rep(j, 0, n) f[j] = f[j] | b[i][j];
    }

    rep(i, 0, n)
    {
        if (!f[i])
        {
            cout << 1 << "\n";
            return;
        }
    }

    dsu uf(n);
    rep(i, 0, n)
    {
        bs a(0);
        a = ~a;
        rep(j, 0, m) if (b[j][i]) a &= b[j];
        rep(j, 0, n) if (a[j]) uf.merge(i, j);
    }
    cout << uf.groups().size() << "\n";
}

int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}
0