QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295487#7514. Clique Challengesofija6WA 4ms11736kbC++233.5kb2023-12-31 08:42:272023-12-31 08:42:27

Judging History

你现在查看的是最新测评结果

  • [2023-12-31 08:42:27]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:11736kb
  • [2023-12-31 08:42:27]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define MAXN 1010
#define MAXS (1<<23)
#define MOD 1000000007
using namespace std;
vector<int> G[MAXN];
bool act[MAXN],dpl[MAXS],dpr[MAXS],edge[MAXN][MAXN];
set<int> s;
ll sum[MAXS],mask1[MAXS],dp[MAXS][25];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,m,u,v;
    cin >> n >> m;
    for (int i=1;i<=m;i++)
    {
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
        edge[u][v]=edge[v][u]=true;
    }
    for (int i=1;i<=n;i++)
    {
        act[i]=true;
        s.insert(i);
    }
    int cnt=n;
    ll ans=0;
    dpl[0]=dpr[0]=true;
    while (cnt)
    {
        int minn=INT_MAX;
        for (int i : s)
        {
            if (act[i])
            {
                int c=0;
                for (ll next : G[i])
                    c+=act[next];
                if (c<minn)
                {
                    minn=c;
                    u=i;
                }
            }
        }
        act[u]=false;
        s.erase(u);
        cnt--;
        vector<ll> w,l,r;
        for (int next : G[u])
        {
            if (act[next])
                w.push_back(next);
        }
        ll x=min(w.size(),(w.size()+1)/2);
        for (int i=0;i<x;i++)
            l.push_back(w[i]);
        for (int i=x;i<w.size();i++)
            r.push_back(w[i]);
        ll m[l.size()+5]={0};
        for (int i=0;i<l.size();i++)
        {
            for (int j=0;j<r.size();j++)
            {
                if (!edge[l[i]][r[j]])
                    m[i]+=(1<<j);
            }
        }
        for (ll i=1;i<(1<<l.size());i++)
        {
            dpl[i]=true;
            ll pos=-1;
            for (int j=0;j<l.size();j++)
            {
                if ((1<<j)&i)
                {
                    if (pos==-1)
                        pos=j;
                    else
                    {
                        if (!edge[l[j]][l[pos]])
                            dpl[i]=false;
                        break;
                    }
                }
            }
            dpl[i]=(dpl[i] && dpl[i^(1<<pos)]);
            mask1[i]=mask1[i^(1<<pos)]|m[pos];
        }
        for (ll i=1;i<(1<<r.size());i++)
        {
            dpr[i]=true;
            ll pos=-1;
            for (int j=0;j<r.size();j++)
            {
                if ((1<<j)&i)
                {
                    if (pos==-1)
                        pos=j;
                    else
                    {
                        if (!edge[r[j]][l[pos]])
                            dpr[i]=false;
                        break;
                    }
                }
            }
            dpr[i]=(dpr[i] && dpr[i^(1<<pos)]);
        }
        for (ll i=0;i<(1<<r.size());i++)
        {
            dp[i][-1]=dpr[i];
            for (ll j=0;j<r.size();j++)
            {
                if (i&(1<<j))
                    dp[i][j]=(dp[i][j-1]+dp[i^(1<<j)][j-1])%MOD;
                else
                    dp[i][j]=dp[i][j-1];
            }
            sum[i]=dp[i][r.size()-1];
        }
        for (ll i=0;i<(1<<l.size());i++)
        {
            if (!dpl[i])
                continue;
            ll mask=(1<<r.size())-1;
            mask^=(mask&mask1[i]);
            ans+=sum[mask];
            if (ans>=MOD)
                ans%=MOD;
        }
    }
    cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9624kb

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 0ms
memory: 11736kb

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 9780kb

input:

1000 100
446 789
167 547
254 777
777 185
33 446
777 847
185 877
757 167
72 383
847 446
254 478
959 185
757 446
847 959
959 167
757 847
747 757
446 167
989 757
547 777
33 747
33 254
254 843
33 547
446 980
877 205
185 72
980 959
33 205
877 757
33 847
478 843
757 478
167 877
72 789
877 959
980 478
167 ...

output:

1386

result:

wrong answer 1st lines differ - expected: '1373', found: '1386'