結果
問題 | No.2742 Car Flow |
ユーザー | t33f |
提出日時 | 2024-04-21 12:50:04 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 3,962 bytes |
コンパイル時間 | 13,687 ms |
コンパイル使用メモリ | 378,360 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 11:21:13 |
合計ジャッジ時間 | 15,614 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
5,248 KB |
testcase_01 | AC | 6 ms
5,248 KB |
testcase_02 | AC | 5 ms
5,248 KB |
testcase_03 | AC | 5 ms
5,248 KB |
testcase_04 | AC | 5 ms
5,248 KB |
testcase_05 | AC | 5 ms
5,248 KB |
testcase_06 | AC | 5 ms
5,248 KB |
testcase_07 | AC | 6 ms
5,248 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 6 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 4 ms
5,248 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 3 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
testcase_16 | AC | 5 ms
5,248 KB |
testcase_17 | AC | 6 ms
5,248 KB |
testcase_18 | AC | 1 ms
5,248 KB |
testcase_19 | AC | 6 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 4 ms
5,248 KB |
testcase_23 | AC | 4 ms
5,248 KB |
testcase_24 | AC | 3 ms
5,248 KB |
testcase_25 | AC | 5 ms
5,248 KB |
testcase_26 | AC | 6 ms
5,248 KB |
testcase_27 | AC | 3 ms
5,248 KB |
testcase_28 | AC | 3 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 5 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 5 ms
5,248 KB |
testcase_33 | AC | 5 ms
5,248 KB |
testcase_34 | AC | 3 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 3 ms
5,248 KB |
testcase_38 | AC | 5 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 1 ms
5,248 KB |
testcase_41 | AC | 1 ms
5,248 KB |
testcase_42 | AC | 1 ms
5,248 KB |
testcase_43 | AC | 1 ms
5,248 KB |
testcase_44 | AC | 1 ms
5,248 KB |
testcase_45 | AC | 1 ms
5,248 KB |
testcase_46 | AC | 1 ms
5,248 KB |
testcase_47 | AC | 1 ms
5,248 KB |
testcase_48 | AC | 1 ms
5,248 KB |
testcase_49 | AC | 1 ms
5,248 KB |
testcase_50 | AC | 0 ms
5,248 KB |
ソースコード
#![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: [usize; n] } // { // let mut b = a.clone(); // for _ in 0..1000 { // let mut c = b.clone(); // for i in 0..n { // c[i] = if { // (b[(i + n - 1) % n] == 1 && b[i] == 0) || // (b[i] == 1 && b[(i + 1) % n] == 1) // } { // 1 // } else { // 0 // } // } // for x in &c { eprint!("{x} "); } // eprintln!(""); // b = c; // } // } let s = a.iter().sum::<usize>(); if s <= n / 2 { println!("{}", MInt::new(s as i64) / MInt::new(n as i64)) } else { println!("{}", MInt::new((n - s) as i64) / MInt::new(n as i64)) } }