結果
| 問題 | 
                            No.1138 No Bingo!
                             | 
                    
| ユーザー | 
                             ikd
                         | 
                    
| 提出日時 | 2020-08-08 21:20:01 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 5,751 bytes | 
| コンパイル時間 | 12,935 ms | 
| コンパイル使用メモリ | 378,860 KB | 
| 実行使用メモリ | 8,064 KB | 
| 最終ジャッジ日時 | 2024-10-02 06:54:43 | 
| 合計ジャッジ時間 | 14,603 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 WA * 11 | 
コンパイルメッセージ
warning: unused imports: `AddAssign`, `Div`
  --> src/main.rs:56:25
   |
56 |     use std::ops::{Add, AddAssign, Div, Mul, Rem, Sub};
   |                         ^^^^^^^^^  ^^^
   |
   = note: `#[warn(unused_imports)]` on by default
warning: unused variable: `i`
   --> src/main.rs:219:9
    |
219 |     for i in 0..10 {
    |         ^ help: if this is intentional, prefix it with an underscore: `_i`
    |
    = note: `#[warn(unused_variables)]` on by default
warning: function `f` is never used
   --> src/main.rs:190:4
    |
190 | fn f(n: usize) -> i32 {
    |    ^
    |
    = note: `#[warn(dead_code)]` on by default
            
            ソースコード
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
mod mint {
    use std::ops::{Add, AddAssign, Div, Mul, Rem, Sub};
    #[derive(Copy, Clone)]
    pub struct Mint<T> {
        x: T,
        mo: T,
    }
    impl<T> Mint<T>
    where
        T: Copy,
        T: Rem<T, Output = T>,
        T: Add<T, Output = T>,
    {
        pub fn new(x: T, mo: T) -> Mint<T> {
            Mint {
                x: (x % mo + mo) % mo,
                mo: mo,
            }
        }
    }
    impl<T> Mint<T>
    where
        T: Copy,
    {
        pub fn val(&self) -> T {
            self.x
        }
        pub fn mo(&self) -> T {
            self.mo
        }
    }
    impl<T> Add<T> for Mint<T>
    where
        T: Copy,
        T: Add<Output = T>,
        T: Rem<Output = T>,
    {
        type Output = Mint<T>;
        fn add(self, rhs: T) -> Mint<T> {
            Mint::new(self.val() + rhs % self.mo(), self.mo())
        }
    }
    impl<T> Add<Mint<T>> for Mint<T>
    where
        T: Copy,
        Mint<T>: Add<T, Output = Mint<T>>,
    {
        type Output = Mint<T>;
        fn add(self, rhs: Mint<T>) -> Mint<T> {
            self + rhs.val()
        }
    }
    impl<T> Sub<T> for Mint<T>
    where
        T: Copy,
        T: Add<Output = T>,
        T: Sub<Output = T>,
        T: Rem<Output = T>,
    {
        type Output = Mint<T>;
        fn sub(self, rhs: T) -> Mint<T> {
            Mint::new(self.val() - rhs % self.mo(), self.mo())
        }
    }
    impl<T> Sub<Mint<T>> for Mint<T>
    where
        T: Copy,
        Mint<T>: Sub<T, Output = Mint<T>>,
    {
        type Output = Mint<T>;
        fn sub(self, rhs: Mint<T>) -> Mint<T> {
            self - rhs.val()
        }
    }
    impl<T> Mul<T> for Mint<T>
    where
        T: Copy,
        T: Add<Output = T>,
        T: Mul<Output = T>,
        T: Rem<Output = T>,
    {
        type Output = Mint<T>;
        fn mul(self, rhs: T) -> Mint<T> {
            Mint::new(self.val() * rhs % self.mo(), self.mo())
        }
    }
    impl<T> Mul<Mint<T>> for Mint<T>
    where
        T: Copy,
        Mint<T>: Mul<T, Output = Mint<T>>,
    {
        type Output = Mint<T>;
        fn mul(self, rhs: Mint<T>) -> Mint<T> {
            self * rhs.val()
        }
    }
    impl<T> std::fmt::Display for Mint<T>
    where
        T: Copy + std::fmt::Display,
    {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(f, "{}", self.val())
        }
    }
}
use mint::Mint;
pub trait NextPermutation {
    fn next_permutation(&mut self) -> bool;
}
impl<T: Ord> NextPermutation for [T] {
    fn next_permutation(&mut self) -> bool {
        if self.is_empty() {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while self[i - 1] >= self[j] {
            j -= 1;
        }
        self.swap(i - 1, j);
        self[i..].reverse();
        return true;
    }
}
fn f(n: usize) -> i32 {
    let mut v = (0..n).collect::<Vec<_>>();
    let mut res = 0;
    loop {
        if v.iter().zip(0..n).all(|(&x, i)| x != i && x != n - i - 1) {
            res += 1;
        }
        if !v.next_permutation() {
            break;
        }
    }
    res
}
fn main() {
    input! {
        n: usize,
    }
    let mo = 998244353;
    let mut a = Mint::new(1, mo);
    for i in 1..=n {
        a = a * Mint::new(i, mo);
    }
    let mut b = vec![Mint::new(0, mo); n + 2];
    b[2] = Mint::new(1, mo);
    for i in 3..=n {
        b[i] = Mint::new(i - 1, mo) * (b[i - 1] + b[i - 2]);
    }
    let b = b[n];
    for i in 0..10 {
        // println!("{} {}", i, f(i));
        // 0 1
        // 1 0
        // 2 0
        // 3 0
        // 4 4
        // 5 16
        // 6 80
        // 7 672
        // 8 4752
        // 9 48768
        // https://oeis.org/A003471
    }
    let mut c = vec![Mint::new(0, mo); n + 2];
    c[0] = Mint::new(1, mo);
    for i in 4..=n {
        if i % 2 == 0 {
            c[i] = Mint::new(i - 1, mo) * c[i - 1] + Mint::new(2 * (i - 2), mo) * c[i - 4];
        } else {
            c[i] = Mint::new(i - 1, mo) * c[i - 1] + Mint::new(2 * (i - 1), mo) * c[i - 2];
        }
    }
    let c = c[n];
    println!("{}", a - b * 2 + c);
}
            
            
            
        
            
ikd