結果

問題 No.382 シャイな人たち (2)
ユーザー xenon_motsuxenon_motsu
提出日時 2020-11-02 18:30:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,333 ms / 8,000 ms
コード長 2,682 bytes
コンパイル時間 3,216 ms
コンパイル使用メモリ 208,236 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 12:12:32
合計ジャッジ時間 79,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,333 ms
4,376 KB
testcase_01 AC 4,236 ms
4,376 KB
testcase_02 AC 3,642 ms
4,376 KB
testcase_03 AC 3,510 ms
4,376 KB
testcase_04 AC 3,465 ms
4,380 KB
testcase_05 AC 3,798 ms
4,380 KB
testcase_06 AC 3,019 ms
4,376 KB
testcase_07 AC 3,995 ms
4,376 KB
testcase_08 AC 3,043 ms
4,380 KB
testcase_09 AC 3,173 ms
4,380 KB
testcase_10 AC 3,361 ms
4,376 KB
testcase_11 AC 3,210 ms
4,376 KB
testcase_12 AC 3,422 ms
4,376 KB
testcase_13 AC 3,489 ms
4,376 KB
testcase_14 AC 3,858 ms
4,376 KB
testcase_15 AC 3,939 ms
4,376 KB
testcase_16 AC 3,465 ms
4,380 KB
testcase_17 AC 3,067 ms
4,380 KB
testcase_18 AC 3,925 ms
4,376 KB
testcase_19 AC 3,534 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

void rec_MIS(int n, std::vector<std::vector<int>>&e, std::vector<bool>&vis, std::vector<int>&d, std::vector<int>&tmp, std::vector<int>&ans){
    int D{}, idx{-1};
    for(int i{};i<n;++i){
        if(vis[i]) continue;
        if(d[i] == 0){
            vis[i]=true;
            tmp.push_back(i);
            rec_MIS(n, e, vis, d, tmp, ans);
            tmp.pop_back();
            vis[i]=false;
            return;
        }
        if(d[i] == 1){
            vis[i]=true;
            for(auto&j:e[i]) if(!vis[j]){
                vis[j]=true;
                for(auto&k:e[j]) --d[k];
                tmp.push_back(i);
                rec_MIS(n, e, vis, d, tmp, ans);
                tmp.pop_back();
                for(auto&k:e[j]) ++d[k];
                vis[j]=false;
                break;
            }
            vis[i]=false;
            return;
        }
        if(D < d[i]){
            D = d[i];
            idx = i;
        }
    }
    if(idx==-1){
        if(ans.size() < tmp.size()) ans = tmp;
        return;
    }
    vis[idx] = true;
    std::vector<int> idxs;
    idxs.reserve(D);
    for(auto&j:e[idx]) if(!vis[j]){
        idxs.push_back(j);
        vis[j]=true;
        for(auto&k:e[j]) --d[k];
    }
    tmp.push_back(idx);
    rec_MIS(n, e, vis, d, tmp, ans);
    tmp.pop_back();
    for(auto&j:idxs){
        vis[j]=false;
        for(auto&k:e[j]) ++d[k];
        if(D>2) --d[j];
    }
    if(D>2){
        rec_MIS(n, e, vis, d, tmp, ans);
        for(auto&j:idxs) ++d[j];
    }
    vis[idx] = false;
}

std::vector<int> MIS(std::vector<std::vector<int>>&e){
    int n = e.size();
    std::vector<bool> vis(n);
    std::vector<int> d;
    d.reserve(n);
    for(auto&v:e) d.push_back(v.size());
    std::vector<int> tmp,ans;
    rec_MIS(n, e, vis, d, tmp, ans);
    return ans;
}

int main(){
    int64_t s;
    constexpr int64_t base = 12345, mod = 1000003;
    std::cin>>s;
    (s*=base) %= mod;
    int n = s%120 + 2;
    (s*=base) %= mod;
    int p = s;
    std::vector<std::vector<int>> e(n);
    for(int i{};i<(n);++i){
        for(int j{i+1};j<n;++j){
            (s*=base) %= mod;
            if(s>=p){
                e[i].push_back(j);
                e[j].push_back(i);
            }
        }
    }
    auto v=MIS(e);
    int N = v.size();
    if(n==N){
        std::cout<<-1<<'\n';
        return 0;
    }
    std::cout<<N+1<<'\n';
    for(int i{};i<(N-1);++i){
        std::cout<<v[i]+1<<" ";
    }
    std::cout<<v.back()+1<<'\n';
}
0