結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 187 ms
4,352 KB
testcase_01 AC 133 ms
4,352 KB
testcase_02 AC 145 ms
4,348 KB
testcase_03 AC 163 ms
4,348 KB
testcase_04 AC 150 ms
4,352 KB
testcase_05 AC 150 ms
4,348 KB
testcase_06 AC 200 ms
4,352 KB
testcase_07 AC 137 ms
4,352 KB
testcase_08 AC 151 ms
4,348 KB
testcase_09 AC 181 ms
4,348 KB
testcase_10 AC 158 ms
4,348 KB
testcase_11 AC 114 ms
4,348 KB
testcase_12 AC 127 ms
4,348 KB
testcase_13 AC 130 ms
4,348 KB
testcase_14 AC 156 ms
4,348 KB
testcase_15 AC 131 ms
4,348 KB
testcase_16 AC 159 ms
4,352 KB
testcase_17 AC 108 ms
4,348 KB
testcase_18 AC 115 ms
4,348 KB
testcase_19 AC 123 ms
4,348 KB
testcase_20 AC 1 ms
4,348 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];
        int m = int(rem.size());
        sort(rem.begin(), rem.end(), [&](P a, P b) { return a.deg > b.deg; });
        int max_c = 1;
        for (int i = 0; i < m; i++) {
            rem[i].col = 0;
            while ((g[rem[i].id] & col_buf[rem[i].col]).any()) rem[i].col++;
            max_c = max(max_c, rem[i].id + 1);
            col_buf[rem[i].col].set(rem[i].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