Submission #62613785


Source Code Expand

Copy
//#[derive_readable]
#[derive(Debug, Clone)]
#[allow(dead_code)]
struct Problem {
n: usize,
xs: Vec<i64>,
}
impl Problem {
fn read() -> Problem {
input! {
n: usize,
xs: [i64; n],
}
Problem { n, xs }
}
fn solve_sub(&self) -> bool {
let n = self.n;
let xs = &self.xs;
if n == 1 {
return true;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//#[derive_readable]
#[derive(Debug, Clone)]
#[allow(dead_code)]
struct Problem {
    n: usize,
    xs: Vec<i64>,
}

impl Problem {
    fn read() -> Problem {
        input! {
            n: usize,
            xs: [i64; n],
        }
        Problem { n, xs }
    }
    fn solve_sub(&self) -> bool {
        let n = self.n;
        let xs = &self.xs;
        if n == 1 {
            return true;
        }
        if n == 2 {
            return false;
        }
        // A_i が偶数である i の数

        let cnt_even = xs.iter().filter(|&&x| x % 2 == 0).count();
        if n == 3 {
            return cnt_even != 3;
        }
        // n = 4: cnt_even % 2 == 1
        // n = 5: cnt_even % 2 == 0
        // n = 6: cnt_even % 2 == 1
        if n % 2 == 0 {
            cnt_even % 2 == 1
        } else {
            cnt_even % 2 == 0
        }
    }
    #[allow(dead_code)]
    fn solve(&self) -> Answer {
        let ans = self.solve_sub();
        Answer { ans }
    }

    #[allow(dead_code)]
    fn solve_naive(&self) -> Answer {
        let xs = &self.xs;

        // 先手勝ち?
        fn rec(xs: &[i64], set: &HashSet<usize>) -> bool {
            if set.len() == xs.len() {
                return false;
            }
            let n = xs.len();

            (0..n).filter(|&i| xs[i] > 0).any(|i| {
                // 相手負け
                let mut next_xs = xs.to_vec();
                next_xs[i] -= 1;
                let mut next_set = set.clone();
                next_set.insert(i);
                !rec(&next_xs, &next_set)
            })
        }

        let ans = rec(xs, &HashSet::new());
        Answer { ans }
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
struct Answer {
    ans: bool, // 先手勝ち?
}

impl Answer {
    fn print(&self) {
        if self.ans {
            // 先手勝ち?
            println!("Fennec");
        } else {
            println!("Snuke");
        }
    }
}

fn main() {
    //Problem::read().solve().print();
    Problem::read().solve().print();
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use super::*;
    #[allow(unused_imports)]
    use rand::{rngs::SmallRng, seq::SliceRandom, *};

    #[test]
    fn test_problem() {
        assert_eq!(1 + 1, 2);
    }

    #[allow(dead_code)]
    #[derive(Debug)]
    struct WrongTestCase {
        problem: Problem,
        main_ans: Answer,
        naive_ans: Answer,
    }

    #[allow(dead_code)]
    fn check(p: &Problem) -> Option<WrongTestCase> {
        let main_ans = p.solve();
        let naive_ans = p.solve_naive();
        if main_ans != naive_ans {
            Some(WrongTestCase {
                problem: p.clone(),
                main_ans,
                naive_ans,
            })
        } else {
            None
        }
    }

    #[allow(dead_code)]
    fn make_random_problem(rng: &mut SmallRng) -> Problem {
        let n = rng.gen_range(1..=8);
        let xs = (0..n).map(|_| rng.gen_range(1..=4)).collect_vec();
        let p = Problem { n, xs };
        println!("{:?}", &p);
        p
    }

    #[allow(unreachable_code)]
    #[test]
    fn test_with_naive() {
        let num_tests = 10;
        let max_wrong_case = 10; // この件数間違いが見つかったら打ち切り
        let mut rng = SmallRng::seed_from_u64(42);
        // let mut rng = SmallRng::from_entropy();
        let mut wrong_cases: Vec<WrongTestCase> = vec![];
        for _ in 0..num_tests {
            let p = make_random_problem(&mut rng);
            let result = check(&p);
            if let Some(wrong_test_case) = result {
                wrong_cases.push(wrong_test_case);
            }
            if wrong_cases.len() >= max_wrong_case {
                break;
            }
        }

        if !wrong_cases.is_empty() {
            for t in &wrong_cases {
                println!("{:?}", t.problem);
                println!("main ans : {:?}", t.main_ans);
                println!("naive ans: {:?}", t.naive_ans);
                println!();
            }
            println!("{} cases are wrong.", wrong_cases.len());
            panic!();
        }
    }
}

// ====== import ======
#[allow(unused_imports)]
use itertools::{chain, iproduct, izip, Itertools};
#[allow(unused_imports)]
use proconio::{
    derive_readable, fastout, input,
    marker::{Bytes, Chars, Usize1},
};
#[allow(unused_imports)]
use std::cmp::Reverse;
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

// ====== output func ======
#[allow(unused_imports)]
use print_vec::*;
pub mod print_vec {

    use itertools::Itertools;
    use proconio::fastout;
    #[fastout]
    pub fn print_vec<T: std::fmt::Display>(arr: &[T]) {
        for a in arr {
            println!("{}", a);
        }
    }
    #[fastout]
    pub fn print_vec_1line<T: std::fmt::Display>(arr: &[T]) {
        let msg = arr.iter().map(|x| format!("{}", x)).join(" ");
        println!("{}", msg);
    }
    #[fastout]
    pub fn print_vec2<T: std::fmt::Display>(arr: &Vec<Vec<T>>) {
        for row in arr {
            let msg = row.iter().map(|x| format!("{}", x)).join(" ");
            println!("{}", msg);
        }
    }
    pub fn print_bytes(bytes: &[u8]) {
        let msg = String::from_utf8(bytes.to_vec()).unwrap();
        println!("{}", msg);
    }
    pub fn print_chars(chars: &[char]) {
        let msg = chars.iter().collect::<String>();
        println!("{}", msg);
    }
    #[fastout]
    pub fn print_vec_bytes(vec_bytes: &[Vec<u8>]) {
        for row in vec_bytes {
            let msg = String::from_utf8(row.to_vec()).unwrap();
            println!("{}", msg);
        }
    }
}

#[allow(unused)]
fn print_yesno(ans: bool) {
    let msg = if ans { "Yes" } else { "No" };
    println!("{}", msg);
}

// ====== snippet ======

Submission Info

Submission Time
Task B - Fennec VS. Snuke 2
User paruma184
Language Rust (rustc 1.70.0)
Score 600
Code Size 5797 Byte
Status AC
Exec Time 8 ms
Memory 5276 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 68
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt
All 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-random-001.txt, 01-random-002.txt, 01-random-003.txt, 01-random-004.txt, 01-random-005.txt, 01-random-006.txt, 01-random-007.txt, 01-random-008.txt, 01-random-009.txt, 01-random-010.txt, 01-random-011.txt, 01-random-012.txt, 01-random-013.txt, 01-random-014.txt, 01-random-015.txt, 02-large-001.txt, 02-large-002.txt, 02-large-003.txt, 02-large-004.txt, 02-large-005.txt, 02-large-006.txt, 02-large-007.txt, 02-large-008.txt, 02-large-009.txt, 02-large-010.txt, 03-small-001.txt, 03-small-002.txt, 03-small-003.txt, 03-small-004.txt, 03-small-005.txt, 03-small-006.txt, 03-small-007.txt, 03-small-008.txt, 03-small-009.txt, 03-small-010.txt, 03-small-011.txt, 03-small-012.txt, 03-small-013.txt, 03-small-014.txt, 03-small-015.txt, 03-small-016.txt, 03-small-017.txt, 03-small-018.txt, 03-small-019.txt, 03-small-020.txt, 03-small-021.txt, 03-small-022.txt, 03-small-023.txt, 03-small-024.txt, 03-small-025.txt, 03-small-026.txt, 03-small-027.txt, 03-small-028.txt, 03-small-029.txt, 03-small-030.txt, 03-small-031.txt, 03-small-032.txt, 03-small-033.txt, 03-small-034.txt, 03-small-035.txt, 03-small-036.txt, 03-small-037.txt, 03-small-038.txt, 03-small-039.txt, 03-small-040.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 1 ms 1968 KB
00-sample-002.txt AC 1 ms 1928 KB
00-sample-003.txt AC 1 ms 2012 KB
01-random-001.txt AC 6 ms 4488 KB
01-random-002.txt AC 4 ms 3280 KB
01-random-003.txt AC 6 ms 4552 KB
01-random-004.txt AC 3 ms 3148 KB
01-random-005.txt AC 5 ms 3924 KB
01-random-006.txt AC 4 ms 3248 KB
01-random-007.txt AC 3 ms 3260 KB
01-random-008.txt AC 7 ms 4588 KB
01-random-009.txt AC 5 ms 3904 KB
01-random-010.txt AC 5 ms 3980 KB
01-random-011.txt AC 2 ms 2472 KB
01-random-012.txt AC 2 ms 2228 KB
01-random-013.txt AC 5 ms 3984 KB
01-random-014.txt AC 1 ms 2080 KB
01-random-015.txt AC 4 ms 3164 KB
02-large-001.txt AC 8 ms 5236 KB
02-large-002.txt AC 8 ms 5100 KB
02-large-003.txt AC 8 ms 5232 KB
02-large-004.txt AC 8 ms 5216 KB
02-large-005.txt AC 8 ms 5204 KB
02-large-006.txt AC 8 ms 5276 KB
02-large-007.txt AC 8 ms 5164 KB
02-large-008.txt AC 8 ms 5236 KB
02-large-009.txt AC 8 ms 5200 KB
02-large-010.txt AC 8 ms 5140 KB
03-small-001.txt AC 1 ms 1964 KB
03-small-002.txt AC 1 ms 2012 KB
03-small-003.txt AC 1 ms 1836 KB
03-small-004.txt AC 1 ms 1992 KB
03-small-005.txt AC 1 ms 2064 KB
03-small-006.txt AC 1 ms 1828 KB
03-small-007.txt AC 1 ms 1884 KB
03-small-008.txt AC 1 ms 1924 KB
03-small-009.txt AC 1 ms 1996 KB
03-small-010.txt AC 1 ms 1912 KB
03-small-011.txt AC 1 ms 2068 KB
03-small-012.txt AC 1 ms 2072 KB
03-small-013.txt AC 1 ms 2072 KB
03-small-014.txt AC 1 ms 1924 KB
03-small-015.txt AC 1 ms 1932 KB
03-small-016.txt AC 1 ms 2044 KB
03-small-017.txt AC 1 ms 1728 KB
03-small-018.txt AC 1 ms 1972 KB
03-small-019.txt AC 1 ms 2056 KB
03-small-020.txt AC 1 ms 1900 KB
03-small-021.txt AC 1 ms 1936 KB
03-small-022.txt AC 1 ms 1932 KB
03-small-023.txt AC 1 ms 2000 KB
03-small-024.txt AC 1 ms 1932 KB
03-small-025.txt AC 1 ms 1896 KB
03-small-026.txt AC 1 ms 1916 KB
03-small-027.txt AC 1 ms 2068 KB
03-small-028.txt AC 1 ms 1956 KB
03-small-029.txt AC 1 ms 1804 KB
03-small-030.txt AC 1 ms 2068 KB
03-small-031.txt AC 1 ms 1936 KB
03-small-032.txt AC 1 ms 1864 KB
03-small-033.txt AC 1 ms 1912 KB
03-small-034.txt AC 1 ms 1896 KB
03-small-035.txt AC 1 ms 1928 KB
03-small-036.txt AC 1 ms 1900 KB
03-small-037.txt AC 1 ms 1884 KB
03-small-038.txt AC 1 ms 1896 KB
03-small-039.txt AC 1 ms 1848 KB
03-small-040.txt AC 1 ms 1964 KB


2025-04-11 (Fri)
20:49:23 +00:00