提交时间:2022-08-09 11:35:54

运行 ID: 55141

#include<bits/stdc++.h> #define int unsigned long long using namespace std; inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+c-'0'; return x; } int a[10000]; int total = 0; int x,y; main() { int n; n = read(); for(int i=1;i<=n;i++){ a[i] = read(); total += a[i]*a[i]; } // cout << total << endl; if(n == 1) { cout << a[1]*a[1] << endl; return 0; } if(n == 2){ cout << (a[1] & a[2])*(a[1] & a[2]) + (a[1] | a[2]) * (a[1] | a[2]) << endl; return 0; } for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { x = a[i] & a[j]; y = a[i] | a[j]; if(total-a[i]*a[i]-a[j]*a[j]+x*x+y*y > total){ total = total-a[i]*a[i]-a[j]*a[j]+x*x+y*y; // cout << total << endl; // cout << "i and j = " << i << " " << j << endl; // cout << x << " " << y << endl; } } } cout << total << endl; return 0; }