結果
| 問題 | No.2742 Car Flow |
| コンテスト | |
| ユーザー |
t33f
|
| 提出日時 | 2024-04-21 12:30:32 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,287 bytes |
| コンパイル時間 | 13,057 ms |
| コンパイル使用メモリ | 380,148 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:58:09 |
| 合計ジャッジ時間 | 14,856 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 WA * 25 |
ソースコード
#![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)
}
t33f