记录编号 446383 评测结果 AAAAAAAAAA
题目名称 按位或最大值 最终得分 100
用户昵称 Gravatar__stdcall 是否通过 通过
代码语言 C++ 运行时间 0.346 s
提交时间 2017-09-08 08:02:10 内存使用 4.29 MiB
显示代码纯文本
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;
int nowarn;

int n, a[1<<20] = {0};

void or_fwt( int *a ) {
	for( int m = 2; m <= (1<<20); m <<= 1 )
		for( int i = 0; i < (1<<20); i += m )
			for( int j = 0; j < (m>>1); ++j )
				a[i+j+(m>>1)] += a[i+j];
}
void or_ifwt( int *a ) {
	for( int m = 2; m <= (1<<20); m <<= 1 )
		for( int i = 0; i < (1<<20); i += m )
			for( int j = 0; j < (m>>1); ++j )
				a[i+j+(m>>1)] -= a[i+j];
}

int main() {
	freopen( "or_max.in", "r", stdin );
	freopen( "or_max.out", "w", stdout );
	nowarn = scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) {
		int x;
		nowarn = scanf( "%d", &x );
		a[x] = 1;
	}
	or_fwt(a);
	for( int i = 0; i < (1<<20); ++i ) a[i] *= a[i];
	or_ifwt(a);
	for( int i = (1<<20)-1; i >= 0; --i )
		if( a[i] ) {
			printf( "%d\n", i );
			break;
		}
	return 0;
}