Submission #62052761


Source Code Expand

use std::collections::BTreeSet;

#[allow(unused_imports)]
use proconio::input;

fn dfs(v: &mut Vec<u64>, i: usize, a: &Vec<u64>, ans: &mut BTreeSet<u64>) {
    if i == a.len() {
        ans.insert(v.iter().fold(0, |acc, &x| acc ^ x));
        return;
    }
    
    for j in 0..v.len() {
        v[j] += a[i]; 
        dfs(v, i+1, a, ans);
        v[j] -= a[i]; 
    }
    v.push(a[i]);
    dfs(v, i+1, a, ans);
    v.pop();
}

fn main() {
    input!{
        n: usize,
        a: [u64; n],
    }

    let mut ans = BTreeSet::new();
    dfs(&mut Vec::new(), 0, &a, &mut ans);
    println!("{}", ans.len());

}


pub trait Debuggable {
    fn debug_string(&self) -> String;
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        use std::iter::repeat;
        if let Some(max_size) = self.iter()
            .enumerate()
            .map(|(i, x)| (format!("{:?}", x).len()).max(format!("{:?}", i).len()))
            .max() {
                let mut idx = String::from("idx |");   
                let mut val = String::from("val |");   
                for (i, xi) in self.iter().enumerate() {
                    idx.push_str(
                        &format!(" {:>w$} |", i, w=max_size)
                    );
                    val.push_str(
                        &format!(" {:>w$} |", xi, w=max_size)
                    );
                }

                format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
            } else {
                format!("idx | \nval |\n")
            }
    }
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!("{{ {} }}", self.iter().join(", "))
    }
}

impl<T, U> Debuggable for std::collections::BTreeMap<T, U> 
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!(
            "{{\n{}\n }}", self.iter()
                .map(|(k, v)| format!("{k} -> {v}, "))
                .join("\n")
        )
    }
}

// lg! マクロの定義
#[macro_export]
macro_rules! lg {
    ($val:expr) => {
        #[cfg(feature = "local")]
        {
            {
                use Debuggable;
                let val = &$val;
                eprintln!(
                    "[{}:{}] {} = \n{}",
                    file!(),
                    line!(),
                    stringify!($val),
                    val.debug_string()
                );
                val
            }
        }
    }
}
    

Submission Info

Submission Time
Task D - Stone XOR
User ardRiriy
Language Rust (rustc 1.70.0)
Score 400
Code Size 2709 Byte
Status AC
Exec Time 1142 ms
Memory 69928 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 39
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 2128 KiB
example_01.txt AC 1 ms 1896 KiB
example_02.txt AC 1 ms 2004 KiB
hand_00.txt AC 69 ms 1808 KiB
hand_01.txt AC 162 ms 2088 KiB
hand_02.txt AC 41 ms 1936 KiB
hand_03.txt AC 463 ms 7408 KiB
hand_04.txt AC 1 ms 2148 KiB
hand_05.txt AC 149 ms 1968 KiB
random_00.txt AC 15 ms 3868 KiB
random_01.txt AC 1 ms 1980 KiB
random_02.txt AC 0 ms 1968 KiB
random_03.txt AC 1 ms 1936 KiB
random_04.txt AC 1020 ms 69728 KiB
random_05.txt AC 67 ms 2000 KiB
random_06.txt AC 2 ms 2148 KiB
random_07.txt AC 1 ms 1932 KiB
random_08.txt AC 76 ms 1968 KiB
random_09.txt AC 3 ms 1924 KiB
random_10.txt AC 153 ms 2292 KiB
random_11.txt AC 5 ms 1960 KiB
random_12.txt AC 6 ms 2052 KiB
random_13.txt AC 433 ms 12504 KiB
random_14.txt AC 41 ms 2480 KiB
random_15.txt AC 1142 ms 69680 KiB
random_16.txt AC 983 ms 69928 KiB
random_17.txt AC 14 ms 4008 KiB
random_18.txt AC 14 ms 3784 KiB
random_19.txt AC 0 ms 1988 KiB
random_20.txt AC 1 ms 1868 KiB
random_21.txt AC 369 ms 9336 KiB
random_22.txt AC 9 ms 2360 KiB
random_23.txt AC 0 ms 2000 KiB
random_24.txt AC 55 ms 3772 KiB
random_25.txt AC 2 ms 1960 KiB
random_26.txt AC 0 ms 1968 KiB
random_27.txt AC 14 ms 1996 KiB
random_28.txt AC 2 ms 1964 KiB
random_29.txt AC 68 ms 2000 KiB