QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#564509#7932. AND-OR closureBreakPlusWA 1ms5844kbC++142.7kb2024-09-15 08:29:192024-09-15 08:29:20

Judging History

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

  • [2024-09-15 08:29:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5844kb
  • [2024-09-15 08:29:19]
  • 提交

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(){ }
const ll B = 40;
ll n,a[200005],w[B+5],fa[B+5],pt[B+5],cnt,ind[B+5],vis[B+5];
vector<ll>E[B+5];
ll find(ll x){ if(x!=fa[x]) fa[x]=find(fa[x]); return fa[x]; }

struct Graph{
	ll N, d[B+5], p, q;
	ll d1[B+5], d2[B+5], d3[B+5];
	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<B;i++) w[i]=(1ll<<B)-1, fa[i]=i;
	for(ll i=1;i<=n;i++){
		a[i]=read();
		for(ll j=0;j<B;j++){
			if((a[i]>>j)&1) vis[j]=1, w[j]&=a[i];
		}
	}
	for(ll i=0;i<B;i++){
		if(!vis[i]) continue;
	}
	for(ll i=0;i<B;i++){
		if(!vis[i]) continue;
		for(ll j=i+1;j<B;j++){
			if(!vis[j]) continue;
			if(((w[i]>>j)&1) && ((w[j]>>i)&1)){
				fa[find(i)] = find(j);
			}
		}
	}
	unordered_set<ll>S;
	for(ll i=0;i<B;i++){
		if(!vis[i]) continue;
		S.insert(find(i));
		for(ll j=0;j<B;j++){
			if(i==j || !vis[j]) continue;
			if((w[i]>>j)&1){
				if(find(i) == find(j)) continue;
				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<B;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;
}

詳細信息

Test #1:

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

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3820kb

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:

53

result:

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