QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283521#7521. Find the Gaplight_ink_dots#WA 1ms5620kbC++142.9kb2023-12-14 18:48:352023-12-14 18:48:36

Judging History

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

  • [2023-12-14 18:48:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5620kb
  • [2023-12-14 18:48:35]
  • 提交

answer

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod=1e9+7;
#define int long long
int s[1<<22];
int id[3000];
vector<int>v[3000];
int e[3000][3000];
int mask[3000],msk[3000];
int solve(vector<int>a){
    // cout<<a.size()<<endl;exit(0);
    memset(id,-1,sizeof(id));
    memset(mask,0,sizeof(mask));
    memset(msk,0,sizeof(msk));
    for(int i=0;i<a.size();i++) id[a[i]]=i;
    int b=a.size()/2;
    int num=(a.size()-b);
    memset(s,0,sizeof(int)*(1<<b));
    // cerr<<"?? "<<num<<" "<<b<<endl;
    for(int i=0;i<a.size();i++){
        for(int j=0;j<num;j++){
            if(e[a[b+j]][a[i]]) mask[i]|=(1<<j);
        }
        for(int j=0;j<b;j++){
            if(e[a[j]][a[i]]) msk[i]|=(1<<j);
        }
    }
    for(int u=0;u<(1<<num);u++){
        bool fl=0;
        int ma=(1<<num)-1;;
        for(int j=0;j<num;j++){
            if(!((u>>j)&1)) continue;
            ma&=mask[j+b];
        }
        if((ma&u)!=u) continue;
        if(fl) continue;
        int mask=(1<<b)-1;
        for(int j=0;j<num;j++){
            if(!((u>>j)&1)) continue;
            int z;
            z=msk[j+b];
            mask&=z;
        }
        s[mask]++;
        // cerr<<mask<<endl;
    }
    for(int mid=1;mid<(1<<b);mid<<=1){
        for(int j=0;j<(1<<b);j+=(mid<<1)){
            for(int k=0;k<mid;k++){
                s[j+k]+=s[j+k+mid];
            }
        }
    }
    long long ans=0;
    for(int u=0;u<(1<<b);u++){
        bool fl=0;
        int ma=(1<<b)-1;
        for(int i=0;i<b;i++){
            if(!((u>>i)&1)) continue;
            ma&=msk[i];
            // for(int j=0;j<b;j++){
            //     if(!((u>>j)&1)) continue;
            //     if(e[a[i]][a[j]]==0){fl=1;break;}
            // }
            // if(fl) break;
        }
        if((ma&u)!=u) continue;
        // if(fl) continue;
        ans+=s[u];ans%=mod;
    }

    return ans%mod;
    // for(int i=0;i<b;i++){
        
    // }
    // for(int i=b;i<a.size();i++){
        
    // }
}
int n,m;
struct e{
    int x,y;
}d[10000];int deg[3020];
int sol(vector<int>&a){
    if(a.empty()){
        return 1;
    }
    sort(a.begin(),a.end(),[&](int u,int v){
        return deg[u]>deg[v];
    });
    int z=a.back();
    vector<int>tmp;
    for(int i=1;i<=n;i++) if(e[i][z]&&i!=z) {
        deg[i]--,tmp.push_back(i);
        e[i][z]=e[z][i]=0;
    }
    a.pop_back();
    // cerr<<"?? "<<z<<" "<<tmp.size()<<endl;
    int cur=solve(tmp);
    // cerr<<"done"<<endl;
    return cur+sol(a);

}
int32_t main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;cin>>x>>y;
        e[x][y]=e[y][x]=1;
        // d[i]=e{x,y};
        deg[x]++,deg[y]++;
    }
    for(int i=1;i<=n;i++) e[i][i]=1;
    vector<int>p;
    for(int i=1;i<=n;i++) p.push_back(i);
    cout<<(sol(p)-1+mod)%mod;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5620kb

input:

8
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

output:

8

result:

wrong answer 1st numbers differ - expected: '1.0000000', found: '8.0000000', error = '7.0000000'