QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564497#7932. AND-OR closureBreakPlusWA 1ms6164kbC++142.6kb2024-09-15 08:03:552024-09-15 08:03:55

Judging History

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

  • [2024-09-15 08:03:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6164kb
  • [2024-09-15 08:03:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb emplace_back
#define fi first
#define se second
#define mkp make_pair
const ll mod = 998244353;
inline ll read() { ll x; scanf("%lld",&x); return x; }
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
	ll ans=1, base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod; b>>=1;
	}
	return ans;
}

void init(){ }
ll n,a[200005],w[45],fa[45],pt[45],cnt,ind[45],vis[45];
vector<ll>E[45];
ll find(ll x){ if(x!=fa[x]) fa[x]=find(fa[x]); return fa[x]; }

struct Graph{
	ll N, d[45], p, q;
	ll d1[45], d2[45], d3[45];
	inline void addedge(ll x,ll y){
		d[x] |= (1<<y);
	}
	ll g[1<<20];
	ll solve(){
		ll p = N/2, q = N-p;
		for(ll i=0;i<p;i++){
			d1[i] = (d[i] & ((1ll<<p)-1));
			d3[i] = (d[i] >> p);
		}
		for(ll i=0;i<q;i++){
			d2[i] = (d[p+i] >> p);
		}
		for(ll i=0;i<(1<<q);i++){
			g[i]=1;
			for(ll j=0;j<q;j++){
				if(((i>>j)&1) && ((i&d2[j])!=d2[j])){
					g[i]=0;
					break;
				}
			}
		}
		for(ll i=0;i<q;i++){
			for(ll j=(1<<q)-1;j>=0;j--){
				if((j>>i)&1)
					g[j^(1<<i)] += g[j];
			}
		}
		ll ans = 0;
		for(ll i=0;i<(1<<p);i++){
			ll flg=1, nd=0;
			for(ll j=0;j<p;j++){
				if(((i>>j)&1)){
					nd |= d3[j];
					if((i&d1[j])!=d1[j]){
						flg=0; break;
					}
				}
			}
			if(flg){
				ans += g[nd];
			}
		}
		return ans;
	}
}G;
void procedure(){
	n=read();
	for(ll i=0;i<40;i++) w[i]=(1ll<<40)-1, fa[i]=i;
	for(ll i=1;i<=n;i++){
		a[i]=read();
		for(ll j=0;j<40;j++){
			if((a[i]>>j)&1) vis[j]=1, w[j]&=a[i];
		}
	}
	for(ll i=0;i<40;i++){
		if(!vis[i]) continue;
		for(ll j=i+1;j<40;j++){
			if(!vis[j]) continue;
			if((w[i]>>j)&(w[j]>>i)&1){
				fa[find(i)] = find(j);
			}
		}
	}
	unordered_set<ll>S;
	for(ll i=0;i<40;i++){
		if(!vis[i]) continue;
		S.insert(find(i));
		for(ll j=0;j<40;j++){
			if(i==j || !vis[j]) continue;
			if((w[i]>>j)&1){
				E[find(i)].pb(find(j));
				ind[find(j)]++;
			}
		}
	}
	queue<ll>q;
	for(auto x: S) if(!ind[x]) q.push(x);
	while(!q.empty()){
		ll x=q.front(); q.pop(); pt[x] = (cnt++);
		for(auto y: E[x]){
			ind[y]--;
			if(!ind[y]) q.push(y);
		}
	}
	G.N = cnt;
	for(ll i=0;i<40;i++){
		if(!vis[i]) continue;
		for(auto j: E[i]){
			G.addedge(pt[i], pt[j]);
		}
	}
	printf("%lld\n", G.solve());
}
int main(){
	#ifdef LOCAL
		assert(freopen("input.txt","r",stdin));
		assert(freopen("output.txt","w",stdout));
	#endif
	ll T=1; init();
	// T=read();
	while(T--) procedure();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5880kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

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:

1

result:

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