比赛 20150420 评测结果 AAAAAAAAAA
题目名称 超牛冠军赛 最终得分 100
用户昵称 Asm.Def 运行时间 0.351 s
代码语言 C++ 内存使用 14.04 MiB
提交时间 2015-04-20 11:02:36
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
//#define USEFREAD
#ifdef USEFREAD
#define InputLen 5000000
char *ptr=(char *)malloc(InputLen);
#define getc() (*(ptr++))
#else
#define getc() (getchar())
#endif
#define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout))
template<class T>inline void getd(T &x){
    char ch = getc();bool neg = false;
    while(!isdigit(ch) && ch != '-')ch = getc();
    if(ch == '-')ch = getc(), neg = true;
    x = ch - '0';
    while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
    if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 2002;
typedef long long LL;
int N, G[maxn][maxn], id[maxn], dis[maxn];
LL ans;
bool known[maxn] = {1};

inline void work(){
	int j, t, Max, tmp, cur;
	for(j = 1;j < N;++j)dis[j] = G[0][j];
	while(1){
		Max = -1;
		for(j = 1;j < N;++j)if(!known[j] && dis[j] > Max)
			Max = dis[j], t = j;
		if(!(~Max))break;
		ans += Max;known[t] = true;
		for(j = 1;j < N;++j)if(!known[j])
			dis[j] = max(dis[j], G[t][j]);
	}
	printf("%lld\n", ans);
}

int main(){
	#ifdef DEBUG
	freopen("test.txt", "r", stdin);
	#else       
	SetFile(superbull);
	#endif
	#ifdef USEFREAD
	fread(ptr,1,InputLen,stdin);
	#endif
	getd(N);for(int i = 0;i < N;++i)getd(id[i]);
	for(int i = 1;i < N;++i)for(int j = 0;j < i;++j)G[j][i] = G[i][j] = id[i] ^ id[j];
	work();
	
#ifdef DEBUG
    printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
    return 0;
}