Submission #28777403


Source Code Expand

use proconio::input;

fn dfs(
    n: usize,
    a: &[Vec<usize>],
    ans: &mut usize,
    pairs: &mut Vec<(usize, usize)>,
    used: &mut Vec<bool>,
    index: usize,
) {
    if index == 2 * n {
        let mut b = 0_usize;
        for (i, j) in pairs.iter().copied() {
            b ^= a[i][j];
        }
        *ans = (*ans).max(b);
        return;
    }

    if index % 2 == 0 {
        for (l, used_l) in used.iter().copied().enumerate() {
            if used_l {
                continue;
            }

            pairs.push((l, 2 * n));
            used[l] = true;
            dfs(n, a, ans, pairs, used, index + 1);
            pairs.pop();
            used[l] = false;
            break;
        }
    } else {
        let l = pairs.pop().unwrap().0;
        for r in l + 1..2 * n {
            if used[r] {
                continue;
            }
            pairs.push((l, r));
            used[r] = true;
            dfs(n, a, ans, pairs, used, index + 1);
            pairs.pop();
            used[r] = false;
        }
        pairs.push((l, 2 * n));
    }
}

fn main() {
    input! {
        n: usize,
    };
    let a = {
        let mut a = vec![];
        for i in 0..2 * n {
            input! {
                a_i: [usize; 2 * n - i - 1]
            }
            a.push(a_i);
        }
        let mut a2 = vec![vec![0; 2 * n]; 2 * n];
        for i in 0..2 * n {
            for j in 0..2 * n - i - 1 {
                a2[i][i + 1 + j] = a[i][j];
                a2[i + 1 + j][i] = a[i][j];
            }
        }
        a2
    };

    let mut ans = 0_usize;
    let mut pairs = vec![];
    let mut used = vec![false; 2 * n];
    dfs(n, &a, &mut ans, &mut pairs, &mut used, 0);

    println!("{}", ans);
}

Submission Info

Submission Time
Task D - Dance
User bouzuya
Language Rust (1.42.0)
Score 400
Code Size 1734 Byte
Status AC
Exec Time 130 ms
Memory 2200 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 28
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 8 ms 2056 KiB
001.txt AC 1 ms 2036 KiB
002.txt AC 130 ms 2080 KiB
003.txt AC 128 ms 2084 KiB
004.txt AC 126 ms 2068 KiB
005.txt AC 2 ms 2116 KiB
006.txt AC 2 ms 1904 KiB
007.txt AC 2 ms 2080 KiB
008.txt AC 3 ms 2132 KiB
009.txt AC 17 ms 2120 KiB
010.txt AC 2 ms 2192 KiB
011.txt AC 19 ms 2136 KiB
012.txt AC 2 ms 2108 KiB
013.txt AC 1 ms 2052 KiB
014.txt AC 2 ms 2084 KiB
015.txt AC 129 ms 2040 KiB
016.txt AC 125 ms 2116 KiB
017.txt AC 128 ms 2112 KiB
018.txt AC 124 ms 2052 KiB
019.txt AC 130 ms 2200 KiB
020.txt AC 126 ms 1968 KiB
021.txt AC 129 ms 2068 KiB
022.txt AC 127 ms 2136 KiB
023.txt AC 126 ms 2196 KiB
024.txt AC 126 ms 2052 KiB
example0.txt AC 1 ms 2060 KiB
example1.txt AC 1 ms 2004 KiB
example2.txt AC 1 ms 1984 KiB