結果

問題 No.382 シャイな人たち (2)
ユーザー yosupotyosupot
提出日時 2019-02-12 18:31:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 8,000 ms
コード長 2,565 bytes
コンパイル時間 2,766 ms
コンパイル使用メモリ 221,688 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-11 10:58:36
合計ジャッジ時間 6,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
4,372 KB
testcase_01 AC 131 ms
4,372 KB
testcase_02 AC 144 ms
4,368 KB
testcase_03 AC 161 ms
4,372 KB
testcase_04 AC 149 ms
4,368 KB
testcase_05 AC 148 ms
4,368 KB
testcase_06 AC 198 ms
4,368 KB
testcase_07 AC 135 ms
4,372 KB
testcase_08 AC 149 ms
4,372 KB
testcase_09 AC 178 ms
4,372 KB
testcase_10 AC 156 ms
4,368 KB
testcase_11 AC 111 ms
4,372 KB
testcase_12 AC 125 ms
4,368 KB
testcase_13 AC 128 ms
4,368 KB
testcase_14 AC 154 ms
4,368 KB
testcase_15 AC 129 ms
4,368 KB
testcase_16 AC 158 ms
4,372 KB
testcase_17 AC 106 ms
4,372 KB
testcase_18 AC 114 ms
4,372 KB
testcase_19 AC 121 ms
4,368 KB
testcase_20 AC 1 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template <int N, class E>
struct MaxClique {
    using B = bitset<N>;
    int n;
    V<B> g, col_buf;
    V<int> clique, now;
    struct P { int id, col, deg; };
    VV<P> rems;
    void dfs(int dps = 0) {
        if (clique.size() < now.size()) clique = now;
        auto& rem = rems[dps];
        sort(rem.begin(), rem.end(), [&](P a, P b) { return a.deg > b.deg; });
        int max_c = 1;
        for (auto& p: rem) {
            p.col = 0;
            while ((g[p.id] & col_buf[p.col]).any()) p.col++;
            max_c = max(max_c, p.id + 1);
            col_buf[p.col].set(p.id);
        }
        for (int i = 0; i < max_c; i++) col_buf[i].reset();
        sort(rem.begin(), rem.end(), [&](P a, P b) { return a.col < b.col; });

        while (!rem.empty()) {
            auto p = rem.back();
            if (now.size() + p.col + 1 <= clique.size()) break;

            auto& nrem = rems[dps + 1]; nrem.clear();
            B bs = B();
            for (auto q: rem) {
                if (g[p.id][q.id]) {
                    nrem.push_back({q.id, -1, 0});
                    bs.set(q.id);
                }
            }
            for (auto& q: nrem) {
                q.deg = (bs & g[q.id]).count();
            }
            now.push_back(p.id);
            dfs(dps + 1);
            now.pop_back();

            rem.pop_back();
        }
    }

    MaxClique(VV<E> _g) : n(int(_g.size())), g(n), col_buf(n), rems(n + 1) {
        for (int i = 0; i < n; i++) {
            rems[0].push_back({i, -1, int(_g[i].size())});
            for (auto e: _g[i]) g[i][e.to] = 1;
        }
        dfs();
    }
};

int main() {
    struct E { int to; };

    ll S;
    cin >> S;
    auto nex = [&]() { return S = (S * 12345) % 1000003; };
    int n = (nex() % 120) + 2;
    VV<E> g(n);
    ll P = nex();
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (nex() < P) {
                g[i].push_back({j});
                g[j].push_back({i});
            }
        }
    }

    auto cl = MaxClique<123, E>(g).clique;

    int k = int(cl.size());
    if (n == k) {
        cout << -1 << endl;
        return 0;
    }
    cout << k + 1 << endl;
    for (int i = 0; i < k; i++) {
        cout << cl[i] + 1 << (i == k - 1 ? '\n' : ' ');
    }
    return 0;
}
0