結果
問題 | No.130 XOR Minimax |
ユーザー |
![]() |
提出日時 | 2019-08-07 11:24:48 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 143 ms / 5,000 ms |
コード長 | 967 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 30,848 KB |
実行使用メモリ | 99,712 KB |
最終ジャッジ日時 | 2024-09-12 22:52:45 |
合計ジャッジ時間 | 2,431 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
main.c: In function 'in': main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 8 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:14:24: note: in expansion of macro 'gc' 14 | int n = 0, c = gc(); | ^~
ソースコード
// yukicoder: No.130 XOR Minimax // 2019.8.7 bal4u #include <stdio.h> #include <stdlib.h> #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } int a[100005]; int calc(int sz, int *a, int b) { int *u, *v, wu, wv, i, ans; if (b < 0) return 0; u = malloc(sizeof(int)*sz), v = malloc(sizeof(int)*sz); wu = wv = 0; for (i = 0; i < sz; i++) { if ((a[i] >> b) & 1) u[wu++] = a[i]; else v[wv++] = a[i]; } if (wu == 0 || wv == 0) ans = calc(sz, a, b-1); else { ans = calc(wu, u, b-1); int t = calc(wv, v, b-1); if (t < ans) ans = t; ans |= 1<<b; } return ans; } int main() { int i, N, ma; N = in(); if (N == 1) { puts("0"); return 0; } ma = 0; for (i = 0; i < N; i++) { a[i] = in(); if (a[i] > ma) ma = a[i]; } i = -1; while (ma) ma >>= 1, i++; printf("%d\n", calc(N, a, i)); return 0; }