QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610790 | #8332. Two in One | hhhyh# | TL | 0ms | 0kb | C++23 | 1.3kb | 2024-10-04 17:25:28 | 2024-10-04 17:25:29 |
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int long long
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
int qp(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
};
void solve()
{
int n;
cin >> n;
vector<int> a(n);
vector<int> cnt(n);
for (int i = 0; i < n; i++)
cin >> a[i], a[i]--, cnt[a[i]]++;
int c = max_element(all(cnt)) - cnt.begin();
int mx = cnt[c];
int lg = __lg(mx);
int ans = mx;
for (int i = 0; i < n; i++)
{
if (i == c)
continue;
ans = max(ans, mx | cnt[i]);
for (int j = lg; j >= 0; j++)
{
if (cnt[i] >> j & 1)
{
if (mx >> j & 1)
{
int g = cnt[i] - (1 << j);
g |= (1 << j) - 1;
ans = max(ans, g | mx);
}
}
}
}
// 选1个mx再选一个谁
// 选一个能补高位的,
cout << ans << endl;
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1 7 1 2 3 4 3 2 1