提出 #27036412
ソースコード 拡げる
#include <bits/stdc++.h>
// #define int long long
#define fi first
#define se second
#define ins insert
#define pb push_back
#define flu fflush(stdout)
#define pii std::pair<int, int>
using std::map;
using std::priority_queue;
using std::queue;
using std::set;
using std::stack;
using std::string;
using std::swap;
using std::unordered_map;
using std::unordered_set;
using std::vector;
int read(int x = 0, bool f = 0, char ch = getchar())
{
while (ch < 48 or ch > 57)
f = ch == 45, ch = getchar();
while (48 <= ch and ch <= 57)
x = x * 10 + ch - 48, ch = getchar();
return f ? -x : x;
}
int pow(int x, int k, int P, int res = 1)
{
for (; k; k >>= 1, x = x * x % P)
if (k & 1)
res = res * x % P;
return res;
}
const int N = 1e6 + 5;
const int P = 998244353;
int n, a[N];
struct Trie
{
int cnt, ch[N * 30][2];
void clear()
{
for (int i = 0; i <= cnt; i++)
ch[i][0] = ch[i][1] = 0;
cnt = 1;
}
void ins(int x)
{
int now = 1;
for (int i = 30; i >= 0; i--)
{
int p = (x >> i) & 1;
if (!ch[now][p])
ch[now][p] = ++cnt;
now = ch[now][p];
}
}
int query(int x)
{
int now = 1, res = 0;
for (int i = 30; i >= 0; i--)
{
int p = (x >> i) & 1;
if (ch[now][p])
now = ch[now][p];
else
res += (1 << i), now = ch[now][p ^ 1];
}
return res;
}
} trie;
int solve(int L, int R, int k)
{
if (k < 0 or L > R)
return 0;
int p = L - 1;
while (p < R and !(a[p + 1] & (1 << k)))
p++;
if ((p - L) & 1)
return std::max(solve(L, p, k - 1), solve(p + 1, R, k - 1));
trie.clear();
int ans = INT_MAX;
for (int i = L; i <= p; i++)
trie.ins(a[i]);
for (int i = p + 1; i <= R; i++)
ans = std::min(ans, trie.query(a[i]));
return ans;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("my_input.in", "r", stdin);
#endif
n = read() * 2;
for (int i = 1; i <= n; i++)
a[i] = read();
std::sort(a + 1, a + 1 + n);
printf("%d\n", solve(1, n, 30));
#ifndef ONLINE_JUDGE
std::cerr << (double)clock() / CLOCKS_PER_SEC << std::endl;
#endif
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - XOR Game |
| ユーザ | TosakaUCW |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 700 |
| コード長 | 2437 Byte |
| 結果 | AC |
| 実行時間 | 106 ms |
| メモリ | 25580 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 700 / 700 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt, 01-044.txt, 01-045.txt, 01-046.txt, 01-047.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 7 ms | 3500 KiB |
| 00-sample-002.txt | AC | 2 ms | 3632 KiB |
| 00-sample-003.txt | AC | 3 ms | 3436 KiB |
| 01-001.txt | AC | 2 ms | 3480 KiB |
| 01-002.txt | AC | 58 ms | 10452 KiB |
| 01-003.txt | AC | 2 ms | 3584 KiB |
| 01-004.txt | AC | 50 ms | 6704 KiB |
| 01-005.txt | AC | 42 ms | 4208 KiB |
| 01-006.txt | AC | 38 ms | 4928 KiB |
| 01-007.txt | AC | 14 ms | 3964 KiB |
| 01-008.txt | AC | 25 ms | 4080 KiB |
| 01-009.txt | AC | 6 ms | 3704 KiB |
| 01-010.txt | AC | 52 ms | 11504 KiB |
| 01-011.txt | AC | 53 ms | 8480 KiB |
| 01-012.txt | AC | 31 ms | 8204 KiB |
| 01-013.txt | AC | 94 ms | 10004 KiB |
| 01-014.txt | AC | 104 ms | 24684 KiB |
| 01-015.txt | AC | 93 ms | 14952 KiB |
| 01-016.txt | AC | 53 ms | 5080 KiB |
| 01-017.txt | AC | 62 ms | 5252 KiB |
| 01-018.txt | AC | 55 ms | 5068 KiB |
| 01-019.txt | AC | 60 ms | 5072 KiB |
| 01-020.txt | AC | 87 ms | 10724 KiB |
| 01-021.txt | AC | 90 ms | 13964 KiB |
| 01-022.txt | AC | 88 ms | 14380 KiB |
| 01-023.txt | AC | 94 ms | 15220 KiB |
| 01-024.txt | AC | 92 ms | 15468 KiB |
| 01-025.txt | AC | 91 ms | 16132 KiB |
| 01-026.txt | AC | 97 ms | 21476 KiB |
| 01-027.txt | AC | 98 ms | 19932 KiB |
| 01-028.txt | AC | 98 ms | 20632 KiB |
| 01-029.txt | AC | 100 ms | 24600 KiB |
| 01-030.txt | AC | 106 ms | 24596 KiB |
| 01-031.txt | AC | 103 ms | 25580 KiB |
| 01-032.txt | AC | 85 ms | 5032 KiB |
| 01-033.txt | AC | 102 ms | 5116 KiB |
| 01-034.txt | AC | 93 ms | 5096 KiB |
| 01-035.txt | AC | 103 ms | 5064 KiB |
| 01-036.txt | AC | 87 ms | 5072 KiB |
| 01-037.txt | AC | 91 ms | 5184 KiB |
| 01-038.txt | AC | 90 ms | 5280 KiB |
| 01-039.txt | AC | 93 ms | 5228 KiB |
| 01-040.txt | AC | 95 ms | 5276 KiB |
| 01-041.txt | AC | 92 ms | 5156 KiB |
| 01-042.txt | AC | 96 ms | 7664 KiB |
| 01-043.txt | AC | 94 ms | 6308 KiB |
| 01-044.txt | AC | 93 ms | 7548 KiB |
| 01-045.txt | AC | 99 ms | 14892 KiB |
| 01-046.txt | AC | 95 ms | 10128 KiB |
| 01-047.txt | AC | 94 ms | 15404 KiB |