結果

問題 No.382 シャイな人たち (2)
ユーザー yosupotyosupot
提出日時 2019-02-12 15:45:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,604 bytes
コンパイル時間 2,651 ms
コンパイル使用メモリ 185,504 KB
実行使用メモリ 12,172 KB
最終ジャッジ日時 2023-10-11 10:55:03
合計ジャッジ時間 21,680 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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); }
#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define rep1(i,N) for(int i=1;i<=(int)(N);i++)
#define fs first
#define sc second
#define pb push_back
#define PB push_back
#define MP make_pair
#define show(x) cerr << #x << " = " << (x) << endl
#define FOR(i, a, b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define all(x) x.begin(),x.end()
#define ALL(x) x.begin(),x.end()
template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template <class E>
struct MaxClique {
    int n;
    VV<int> g;
    V<int> clique, now;
    struct P { int id, col; };
    void coloring(V<P>& v) {
        int m = int(v.size());
        for (int i = 0; i < m; i++) {
            v[i].col = 1;
            for (int j = 0; j < i; j++) {
                if (g[v[i].id][v[j].id]) {
                    v[i].col = max(v[i].col, v[j].col + 1);
                }
            }
        }
        sort(v.begin(), v.end(), [&](P a, P b) { return a.col < b.col; });
    }
    void dfs(V<P> rem) {
        if (clique.size() < now.size()) {
            cerr << "REF: " << now.size() << endl;
            clique = now;
        }
        while (!rem.empty()) {
            for (auto p: rem) {
                int i = p.id;
                int er = 0;
                for (auto q: rem) {
                    if (!g[i][q.id]) er++;
                }
                if (er > 2) continue;
                now.push_back(i);
                V<P> nrem;
                for (auto q: rem) {
                    if (g[i][q.id]) nrem.push_back({q.id, -1});
                }
                coloring(nrem);
                dfs(nrem);
                now.pop_back();
                return;
            }
            auto p = rem.back();
            int i = p.id;
            if (now.size() + p.col > clique.size()) {
                now.push_back(i);
                V<P> nrem;
                for (auto q: rem) {
                    if (g[i][q.id]) nrem.push_back({q.id, -1});
                }
                coloring(nrem);
                dfs(nrem);
                now.pop_back();
            }
            rem.pop_back();
        }
    }

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


struct E { int to; };
ll nex(ll S) {
    return (S * 12345) % 1000003;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

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

    auto st = MaxClique<E>(g).clique;

    int k = int(st.size());

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

/*
int main() {
    int n, m;
    cin >> n >> m;
    VV<int> mp(n, V<int>(n, 1));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        mp[a][b] = mp[b][a] = 0;
    }
    struct E { int to; };
    VV<E> g(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (!mp[i][j]) continue;
            g[i].push_back({j});
            g[j].push_back({i});
        }
    }

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

    cout << cl.size() << endl;
}*/
/*
int main() {
    int n, d;
    cin >> n >> d;
    V<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    struct E { int to; };
    VV<E> g(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if ((a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]) <= d * d) {
                g[i].push_back({j});
                g[j].push_back({i});
            }
        }
    }
    auto cl = MaxClique<E>(g).clique;
    cout << cl.size() << endl;
    for (int x: cl) cout << x + 1 << " ";
    cout << endl;
}*/
0