結果
問題 | No.2299 Antitypoglycemia |
ユーザー |
|
提出日時 | 2023-05-12 23:24:15 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 2,905 bytes |
コンパイル時間 | 15,001 ms |
コンパイル使用メモリ | 376,984 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-28 20:14:25 |
合計ジャッジ時間 | 14,202 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
use std::{ops::*, fmt::*, mem::*};const MOD: isize = 998244353;//const MOD: isize = 1000000007;#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]struct Modint {x: isize}impl Modint {fn new(mut x: isize) -> Self {if x < 0 { while x < 0 { x += MOD } }else { x %= MOD }Self { x: x }}fn inv(self) -> Self { //逆元let mut a = self.x;let mut b = MOD;let mut u: isize = 1;let mut v: isize = 0;while b != 0 {let t = a / b;a -= t * b;u -= t * v;swap(&mut a, &mut b);swap(&mut u, &mut v);}Modint::new(u)}}impl Add for Modint {type Output = Modint;fn add(self, rhs: Modint) -> Self {Self::new(self.x + rhs.x)}}impl AddAssign for Modint {fn add_assign(&mut self, rhs: Self) {self.x = (*self + rhs).x;}}impl Sub for Modint {type Output = Modint;fn sub(self, rhs: Modint) -> Self {Self::new(self.x - rhs.x + MOD)}}impl SubAssign for Modint {fn sub_assign(&mut self, rhs: Self) {self.x = (*self - rhs).x;}}impl Mul for Modint {type Output = Modint;fn mul(self, rhs: Modint) -> Self {Self::new(self.x * rhs.x)}}impl MulAssign for Modint {fn mul_assign(&mut self, rhs: Self) {self.x = (*self * rhs).x;}}impl Div for Modint {type Output = Modint;fn div(self, rhs: Self) -> Self {self * rhs.inv()}}impl DivAssign for Modint {fn div_assign(&mut self, rhs: Self) {self.x = (*self / rhs).x;}}impl Display for Modint {fn fmt(&self, f: &mut Formatter<'_>) -> Result {write!(f, "{}", self.x)}}fn fac(n: isize) -> isize {if n <= 1 {return 1} else {return (n * fac(n - 1)) % MOD}}fn main() {let (n, a, b): (usize, usize, usize) = { // 定数個の整数を受け取り, 定数個の変数に束縛するlet mut line: String = String::new();std::io::stdin().read_line(&mut line).unwrap();let mut iter = line.split_whitespace();(iter.next().unwrap().parse().unwrap(),iter.next().unwrap().parse().unwrap(),iter.next().unwrap().parse().unwrap())};if n == 2 {if a == b {println!("{}", 0);return} else {println!("{}", 1);return}}let ans: Modint;if a == b {ans = Modint::new(n as isize - 1) * Modint::new(n as isize - 2) * Modint::new(fac(n as isize - 2));} else {ans = Modint::new(n as isize - 2) * Modint::new(n as isize - 2) * Modint::new(fac(n as isize - 2))+ Modint::new(n as isize - 1) * Modint::new(fac(n as isize - 2))}println!("{}", ans);}