QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#374674 | #8316. Random Permutation | PetroTarnavskyi# | WA | 1ms | 3528kb | C++20 | 1.5kb | 2024-04-02 16:42:52 | 2024-04-02 16:42:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 100'447;
const int INF = 1e9 + 47;
int n;
int a[N];
int find(int l, int r, int bit)
{
FOR (i, l, r)
if (a[i] & (1 << bit))
return i;
return r;
}
int brute(int l, int r)
{
VI nums;
FOR (i, l, r)
nums.PB(a[i]);
int ans = 0;
FOR (i, 0, 1 << SZ(nums))
{
VI f[2];
FOR (j, 0, SZ(nums))
{
f[(i >> j) & 1].PB(nums[j]);
}
VI res(2, INF);
FOR (t, 0, 2)
{
FOR (j, 0, SZ(f[t]))
{
FOR (k, j + 1, SZ(f[t]))
res[t] = min(res[t], f[t][j] ^ f[t][k]);
}
}
ans = max(ans, min(res[0], res[1]));
}
return ans;
}
int solve(int l, int r, int bit)
{
if (bit == -1)
{
if (r - l > 2)
return 0;
return INF;
}
int m = find(l, r, bit);
if (m - l > 2 || r - m > 2)
return min(solve(l, m, bit - 1), solve(m, r, bit - 1));
else
return brute(l, r);
}
void solve()
{
cin >> n;
FOR (i, 0, n) cin >> a[i];
sort(a, a + n);
cout << solve(0, n, 30) << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3528kb
input:
2
output:
1000000047 1000000047
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '1000000047.0000000', error = '1000000046.0000000'