Submission #18218659


Source Code Expand

Copy
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

ll dp[(1<<20)+5];
ll ng[50];

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m);
    rep(i,m) cin >> a[i] >> b[i];
    rep(i,m) --a[i],--b[i];
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    rep(i,n){
        ll mask = 0;
        rep(j,m){
            if(a[j] == i) mask += 1LL<<b[j];
            else if(b[j] == i) mask += 1LL<<a[j];
        }
        ng[i] = mask;
    }
    rep(bit,1<<(n/2)){
        bool ok = true;
        rep(i,n/2){
            if(bit>>i&1LL){
                if((ng[i] & bit) > 0) ok = false;
            }
        }
        if(ok) dp[bit] = __builtin_popcountll(bit);
        else{
            rep(i,n/2){
                if(bit>>i&1LL) chmax(dp[bit],dp[bit^(1LL<<i)]);
            }
        }
    }

    ll ans = 0;
    rep(bit,1<<((n+1)/2)){
        bool ok = true;
        rep(i,(n+1)/2){
            if(bit>>i&1LL){
                if((ng[n/2+i] & (bit<<(n/2))) > 0) ok = false;
            }
        }
        if(ok){
            ll mask = 0;
            rep(i,(n+1)/2){
                if(bit>>i&1) mask |= ng[n/2+i];
            }
            mask &= (1LL<<(n/2))-1LL;
            mask ^= (1LL<<(n/2))-1LL;
            chmax(ans,dp[mask]+__builtin_popcountll(bit));
        }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task G - Mixture Drug
User kapibara
Language C++ (GCC 9.2.1)
Score 600
Code Size 1765 Byte
Status AC
Exec Time 213 ms
Memory 11808 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 51
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_2.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_3.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt, subtask_1_33.txt, subtask_1_34.txt, subtask_1_35.txt, subtask_1_36.txt, subtask_1_37.txt, subtask_1_38.txt, subtask_1_39.txt, subtask_1_4.txt, subtask_1_40.txt, subtask_1_41.txt, subtask_1_42.txt, subtask_1_43.txt, subtask_1_44.txt, subtask_1_45.txt, subtask_1_46.txt, subtask_1_47.txt, subtask_1_48.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt AC 8 ms 3572 KB
sample_02.txt AC 2 ms 3384 KB
sample_03.txt AC 2 ms 3416 KB
subtask_1_1.txt AC 2 ms 3460 KB
subtask_1_10.txt AC 190 ms 11740 KB
subtask_1_11.txt AC 3 ms 3468 KB
subtask_1_12.txt AC 185 ms 11640 KB
subtask_1_13.txt AC 166 ms 7568 KB
subtask_1_14.txt AC 213 ms 11580 KB
subtask_1_15.txt AC 2 ms 3476 KB
subtask_1_16.txt AC 177 ms 11588 KB
subtask_1_17.txt AC 186 ms 11796 KB
subtask_1_18.txt AC 182 ms 11608 KB
subtask_1_19.txt AC 5 ms 3424 KB
subtask_1_2.txt AC 185 ms 11648 KB
subtask_1_20.txt AC 172 ms 11768 KB
subtask_1_21.txt AC 186 ms 11772 KB
subtask_1_22.txt AC 180 ms 11768 KB
subtask_1_23.txt AC 3 ms 3576 KB
subtask_1_24.txt AC 17 ms 4044 KB
subtask_1_25.txt AC 186 ms 11764 KB
subtask_1_26.txt AC 185 ms 11688 KB
subtask_1_27.txt AC 181 ms 11668 KB
subtask_1_28.txt AC 184 ms 11668 KB
subtask_1_29.txt AC 184 ms 11728 KB
subtask_1_3.txt AC 35 ms 4504 KB
subtask_1_30.txt AC 2 ms 3572 KB
subtask_1_31.txt AC 3 ms 3504 KB
subtask_1_32.txt AC 5 ms 3428 KB
subtask_1_33.txt AC 21 ms 3724 KB
subtask_1_34.txt AC 169 ms 11580 KB
subtask_1_35.txt AC 180 ms 11664 KB
subtask_1_36.txt AC 181 ms 11644 KB
subtask_1_37.txt AC 186 ms 11612 KB
subtask_1_38.txt AC 184 ms 11808 KB
subtask_1_39.txt AC 183 ms 11776 KB
subtask_1_4.txt AC 180 ms 11796 KB
subtask_1_40.txt AC 185 ms 11672 KB
subtask_1_41.txt AC 185 ms 11736 KB
subtask_1_42.txt AC 182 ms 11796 KB
subtask_1_43.txt AC 193 ms 11692 KB
subtask_1_44.txt AC 180 ms 11720 KB
subtask_1_45.txt AC 183 ms 11764 KB
subtask_1_46.txt AC 207 ms 11584 KB
subtask_1_47.txt AC 181 ms 11608 KB
subtask_1_48.txt AC 159 ms 11720 KB
subtask_1_5.txt AC 51 ms 5656 KB
subtask_1_6.txt AC 182 ms 11668 KB
subtask_1_7.txt AC 67 ms 5592 KB
subtask_1_8.txt AC 179 ms 11692 KB
subtask_1_9.txt AC 92 ms 7556 KB