結果

問題 No.699 ペアでチームを作ろう2
ユーザー akakimidori
提出日時 2021-04-16 19:24:57
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 974 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,238 ms
コンパイル使用メモリ 188,928 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-24 04:41:54
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// ---------- begin next_permutation ----------
fn next_permutation<T: Ord>(a: &mut [T]) -> bool {
    a.windows(2).rposition(|a| a[0] < a[1]).map_or(false, |x| {
        let y = a.iter().rposition(|b| a[x] < *b).unwrap();
        a.swap(x, y);
        a[(x + 1)..].reverse();
        true
    })
}
// ---------- end next_permutation ----------

fn read() -> Vec<u32> {
    let mut s = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let mut next = || it.next().unwrap().parse::<u32>().unwrap();
    let n = next();
    (0..n).map(|_| next()).collect()
}

fn main() {
    let mut a = read();
    a.sort();
    let mut ans = 0;
    while {
        let mut xor = 0;
        for a in a.chunks_exact_mut(2) {
            xor ^= a[0] + a[1];
            a.sort_by_key(|a| !*a);
        }
        ans = ans.max(xor);
        next_permutation(&mut a)
    } {}
    println!("{}", ans);
}
0