QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#344092#7932. AND-OR closurepoiWA 12ms14176kbC++142.3kb2024-03-03 15:56:572024-03-03 15:56:57

Judging History

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

  • [2024-03-03 15:56:57]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:14176kb
  • [2024-03-03 15:56:57]
  • 提交

answer

#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
#define P 1000000007
const int MAXN = 2e6 + 20;
int n , m;
ll A[MAXN];
ll suf[44];
ll num[MAXN];

void sums( int a[] , int len ) {
	for( int mid = 2 ; mid <= len ; mid <<= 1 ) 
		for( int i = 0 ; i < len ; i += mid )
			for( int j = i ; j < i + ( mid >> 1 ) ; ++ j )
				a[j + ( mid >> 1 )] += a[j];
}

void solve() {
	cin >> n;
	int u0 = 0 , ss = -1;
	rep( i , 1 , n ) {
		scanf("%lld",A + i);
		ss &= A[i];
	}
	if( !ss ) ++ u0;
	vi vec;
	rep( k , 0 , 39 ) {
		ll f = -1;
		rep( i , 1 , n ) {
			if( A[i] & ( 1ll << k ) ) f &= A[i];
		} 
		if( ~f ) vec.pb( f );
	}
	sort( vec.begin() , vec.end() , []( int a , int b ) { return __builtin_popcount( a ) > __builtin_popcount( b ); } );
	int sz = vec.size();
	int ls = sz / 2 , rs = sz - ls;
	rep( i , 0 , sz - 1 ) {
		rep( j , i + 1 , sz - 1 ) {
			if( ( vec[i] & vec[j] ) == vec[j] ) suf[i] |= ( 1ll << j );
		}
	}
	// for( int x : vec ) {
	// 	cout << x << endl;
	// }
	// rep( i , 0 , sz - 1 ) cout << suf[i] << ' '; puts("");

	for( int s = 0 ; s < ( 1 << rs ) ; ++ s ) {
		int flg = 0;
		rep( i , 0 , rs - 1 ) if( s & ( 1 << i ) ) {
			if( suf[i + ls] & ( s << ls ) ) {
				flg = 1; break;
			}
		}
		if( flg ) continue;
		++ num[s];
	}

	sums( num , 1 << 20 );

	ll ans = 0;
	for( int s = 0 ; s < ( 1 << ls ) ; ++ s ) {
		int flg = 0 , ns = 0;
		rep( i , 0 , ls - 1 ) if( s & ( 1 << i ) ) {
			if( suf[i] & s ) {
				flg = 1; break;
			}
			ns |= ( suf[i] >> ls );
		}
		if( flg ) continue;
		ans += num[( ~ns ) & ( ( 1 << 20 ) - 1 )];
		// cout << ans << endl;
	}
	cout << ans - 1 + u0 << endl;
} 

signed main() {
    // freopen("bird.in","r",stdin),freopen("bird.out","w",stdout);
//    int T;cin >> T;while( T-- ) solve();
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 14176kb

input:

4
0 1 3 5

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 7ms
memory: 14176kb

input:

5
0 1 2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: -100
Wrong Answer
time: 12ms
memory: 13944kb

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:

1229

result:

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