結果

問題 No.699 ペアでチームを作ろう2
ユーザー akakimidoriakakimidori
提出日時 2021-04-16 19:24:57
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 974 bytes
コンパイル時間 5,646 ms
コンパイル使用メモリ 150,304 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 19:10:23
合計ジャッジ時間 2,388 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// ---------- 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