結果

問題 No.2742 Car Flow
ユーザー t33ft33f
提出日時 2024-04-21 12:30:32
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,287 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 166,888 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:30:36
合計ジャッジ時間 3,295 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 6 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 3 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 6 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 WA -
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 6 ms
5,376 KB
testcase_39 WA -
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 1 ms
5,376 KB
testcase_46 WA -
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
use proconio::{input};

mod mod_int {
use core::iter::Sum;
use core::ops::*;

#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
pub struct ModInt<const MOD: i32> {
    value: i32
}

impl<const MOD: i32> ModInt<MOD> {
    fn normalize(v: i64) -> i32 {
        if 0 <= v && v < MOD as i64 {
            v as i32
        } else {
            let v1 = (v % MOD as i64) as i32;
            if v1 < 0 { v1 + MOD } else { v1 }
        }
    }
    pub fn new(v: i64) -> ModInt<MOD> { ModInt{ value: Self::normalize(v) } }
    pub fn inverse(self) -> Self {
        let mut x = MOD as i64;
        let mut y = self.value as i64;
        let mut p = 1;
        let mut q = 0;
        let mut r = 0;
        let mut s = 1;
        while y != 0 {
            let u = x / y;
            let x0 = y; y = x - y * u; x = x0;
            let r0 = p - r * u;
            let s0 = q - s * u;
            p = r; r = r0; q = s; s = s0;
        }
        ModInt::new(q)
    }
}

impl<const MOD: i32> std::fmt::Display for ModInt<MOD> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.value)
    }
}

impl<const MOD: i32> Add<Self> for ModInt<MOD> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        let value = self.value as i64 + rhs.value as i64;
        let value = (if value < MOD as i64 { value } else { value - MOD as i64 }) as i32;
        ModInt{ value }
    }
}

impl<const MOD: i32> Add<i64> for ModInt<MOD> {
    type Output = Self;
    fn add(self, rhs: i64) -> Self {
        self + ModInt::new(rhs)
    }
}

impl<const MOD: i32> Sub<Self> for ModInt<MOD> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        let value = self.value as i64 - rhs.value as i64;
        let value = (if value >= 0 { value } else { value + MOD as i64 }) as i32;
        ModInt{ value }
    }
}

impl<const MOD: i32> Sub<i64> for ModInt<MOD> {
    type Output = Self;
    fn sub(self, rhs: i64) -> Self {
        self - ModInt::new(rhs)
    }
}

impl<const MOD: i32> AddAssign<Self> for ModInt<MOD> {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs
    }
}

impl<const MOD: i32> AddAssign<i64> for ModInt<MOD> {
    fn add_assign(&mut self, rhs: i64) {
        *self = *self + rhs
    }
}

impl<const MOD: i32> Mul<Self> for ModInt<MOD> {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        Self::new(self.value as i64 * rhs.value as i64)
    }
}

impl<const MOD: i32> MulAssign<Self> for ModInt<MOD> {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs
    }
}

impl<const MOD: i32> Div<Self> for ModInt<MOD> {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        self * rhs.inverse()
    }
}

impl<const MOD: i32> Div<i64> for ModInt<MOD> {
    type Output = Self;
    fn div(self, rhs: i64) -> Self {
        self / ModInt::new(rhs)
    }
}

impl<const MOD: i32> Sum<Self> for ModInt<MOD> {
    fn sum<I: Iterator<Item=Self>>(iter: I) -> Self {
        iter.fold(Self::new(0), |a, b| a + b)
    }
}
}

const MOD: i32 = 998244353;
type MInt = mod_int::ModInt::<MOD>;

fn main() {
    input!{ n: usize, a: [i32; n] }
    let s: MInt = a.iter().map(|x| MInt::new(*x as i64)).sum::<_>();
    println!("{}", s / n as i64)
}
0