Submission #18218597


Source Code Expand

Copy
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(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;

int dp[1<<20+5];
int ng[50];

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> 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){
        int mask = 0;
        rep(j,m){
            if(a[j] == i) mask += 1<<b[j];
            else if(b[j] == i) mask += 1<<a[j];
        }
        ng[i] = mask;
    }
    rep(bit,1<<(n/2)){
        bool ok = true;
        rep(i,n/2){
            if(bit>>i&1){
                if((ng[i] & bit) > 0) ok = false;
            }
        }
        if(ok) dp[bit] = __builtin_popcount(bit);
        else{
            rep(i,n/2){
                if(bit>>i&1) chmax(dp[bit],dp[bit^(1<<i)]);
            }
        }
    }

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

Submission Info

Submission Time
Task G - Mixture Drug
User kapibara
Language C++ (GCC 9.2.1)
Score 0
Code Size 1748 Byte
Status WA
Exec Time 232 ms
Memory 7688 KB

Compile Error

./Main.cpp:15:13: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
   15 | int dp[1<<20+5];
      |           ~~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 22
WA × 29
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 5 ms 3472 KB
sample_02.txt AC 6 ms 3424 KB
sample_03.txt AC 5 ms 3540 KB
subtask_1_1.txt AC 2 ms 3596 KB
subtask_1_10.txt AC 185 ms 7636 KB
subtask_1_11.txt AC 3 ms 3396 KB
subtask_1_12.txt WA 183 ms 7520 KB
subtask_1_13.txt AC 165 ms 5628 KB
subtask_1_14.txt AC 204 ms 7488 KB
subtask_1_15.txt AC 2 ms 3608 KB
subtask_1_16.txt WA 187 ms 7636 KB
subtask_1_17.txt WA 178 ms 7688 KB
subtask_1_18.txt WA 176 ms 7680 KB
subtask_1_19.txt AC 4 ms 3636 KB
subtask_1_2.txt AC 177 ms 7632 KB
subtask_1_20.txt WA 183 ms 7584 KB
subtask_1_21.txt WA 179 ms 7684 KB
subtask_1_22.txt WA 174 ms 7568 KB
subtask_1_23.txt AC 2 ms 3520 KB
subtask_1_24.txt AC 15 ms 3844 KB
subtask_1_25.txt AC 180 ms 7576 KB
subtask_1_26.txt WA 179 ms 7628 KB
subtask_1_27.txt WA 175 ms 7572 KB
subtask_1_28.txt WA 178 ms 7548 KB
subtask_1_29.txt WA 174 ms 7636 KB
subtask_1_3.txt WA 45 ms 3996 KB
subtask_1_30.txt AC 2 ms 3584 KB
subtask_1_31.txt AC 2 ms 3400 KB
subtask_1_32.txt AC 5 ms 3608 KB
subtask_1_33.txt AC 14 ms 3652 KB
subtask_1_34.txt WA 180 ms 7544 KB
subtask_1_35.txt WA 178 ms 7552 KB
subtask_1_36.txt WA 176 ms 7572 KB
subtask_1_37.txt WA 177 ms 7580 KB
subtask_1_38.txt WA 202 ms 7684 KB
subtask_1_39.txt WA 209 ms 7684 KB
subtask_1_4.txt WA 206 ms 7584 KB
subtask_1_40.txt WA 207 ms 7584 KB
subtask_1_41.txt WA 177 ms 7500 KB
subtask_1_42.txt WA 208 ms 7620 KB
subtask_1_43.txt WA 232 ms 7632 KB
subtask_1_44.txt WA 185 ms 7684 KB
subtask_1_45.txt AC 177 ms 7576 KB
subtask_1_46.txt AC 206 ms 7676 KB
subtask_1_47.txt WA 184 ms 7688 KB
subtask_1_48.txt WA 176 ms 7524 KB
subtask_1_5.txt WA 49 ms 4420 KB
subtask_1_6.txt WA 182 ms 7572 KB
subtask_1_7.txt WA 72 ms 4500 KB
subtask_1_8.txt AC 181 ms 7576 KB
subtask_1_9.txt AC 94 ms 5448 KB