QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414189#7932. AND-OR closurei_am_noob#WA 1ms5712kbC++142.1kb2024-05-18 16:45:422024-05-18 16:45:43

Judging History

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

  • [2024-05-18 16:45:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5712kb
  • [2024-05-18 16:45:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using pii=pair<int,int>;
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())

const int N=1<<18,M=40;
int n,scc[M],scc_cnt,tot[1<<20];
ll a[N],g[M],rg[M],all_bit,scc_g[M];
bool vis[M];
vector<int> ord;

void rdfs(int u){
    vis[u]=1;
    for(int v=0; v<M; ++v) if((rg[u]>>v&1)&&!vis[v]) rdfs(v);
    ord.pb(u);
}

void dfs(int u){
    vis[u]=1,scc[u]=scc_cnt;
    for(int v=0; v<M; ++v) if((g[u]>>v&1)&&!vis[v]) dfs(v);
}

void ahcorz(){
    cin >> n;
    for(int i=0; i<n; ++i) cin >> a[i];
    for(int i=0; i<M; ++i){
        int cnt=0;
        for(int j=0; j<n; ++j) cnt+=a[j]>>i&1;
        if(cnt>=1&&cnt<n) all_bit|=1<<i;
    }
    for(int i=0; i<M; ++i) if(all_bit>>i&1){
        ll cur=all_bit;
        for(int j=0; j<n; ++j) if(a[j]>>i&1) cur&=a[j];
        g[i]=cur;
        for(int j=0; j<M; ++j) if(g[i]>>j&1) rg[j]|=1ll<<i;
    }
    for(int i=0; i<M; ++i) if((all_bit>>i&1)&&!vis[i]) rdfs(i);
    reverse(all(ord));
    memset(vis,0,sizeof vis);
    for(auto i: ord) if(!vis[i]) dfs(i),scc_cnt++;
    //cout << scc_cnt << endl;
    for(int i=0; i<M; ++i) for(int j=0; j<M; ++j) if((g[i]>>j&1)) scc_g[scc[i]]|=1ll<<scc[j];
    for(int i=0; i<scc_cnt; ++i) for(int j=0; j<i; ++j) if(scc_g[i]>>j&1) scc_g[i]|=scc_g[j];
    //for(int i=0; i<scc_cnt; ++i) cout << scc_g[i] << endl;
    int m=min(20,scc_cnt);
    for(int s=0; s<(1<<m); ++s){
        bool f=1;
        for(int i=0; i<m; ++i) if((s>>i&1)&&(scc_g[i]&s)!=scc_g[i]) f=0;
        if(f) tot[s]++;
    }
    for(int i=0; i<m; ++i) for(int j=0; j<(1<<m); ++j) if(~j>>i&1) tot[j]+=tot[j|(1<<i)];
    ll res=0;
    for(int s=0; s<(1<<(scc_cnt-m)); ++s){
        bool f=1;
        for(int i=m; i<scc_cnt; ++i) if((s>>(i-m)&1)&&((scc_g[i]>>m)&s)!=(scc_g[i]>>m)) f=0;
        if(f){
            int s2=0;
            for(int i=m; i<scc_cnt; ++i) if(s>>(i-m)&1) s2|=(scc_g[i]&((1<<m)-1));
            res+=tot[s2];
        }
    }
    cout << res << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int t=1; //cin >> t;
    while(t--) ahcorz();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5712kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5656kb

input:

49
1097363587067 1096810445814 275012137504 1096739142630 1096809921522 1087071335264 829364908576 949625500192 1087142638448 1096200190829 1097292808175 1095750860656 1087144145776 1097346808827 1095734082416 1096755396578 829230678048 1095663303524 1087072842592 1096216444777 949623992864 10962714...

output:

51

result:

wrong answer 1st numbers differ - expected: '52', found: '51'