結果
問題 | No.2299 Antitypoglycemia |
ユーザー | so-hey |
提出日時 | 2023-05-12 23:06:29 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,172 bytes |
コンパイル時間 | 15,603 ms |
コンパイル使用メモリ | 378,844 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-06 13:08:37 |
合計ジャッジ時間 | 16,841 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 0 ms
5,248 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | WA | - |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
warning: value assigned to `ans` is never read --> src/main.rs:114:13 | 114 | let mut ans = Modint::new(0); | ^^^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default warning: method `pow` is never used --> src/main.rs:30:8 | 9 | impl Modint { | ----------- method in this implementation ... 30 | fn pow(self, n: isize) -> Self { | ^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
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(x: isize) -> Self { if x < 0 { Self {x: x + MOD} } else { Self {x: x % MOD} } } 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); } Self { x: (u % MOD + MOD) % MOD } } fn pow(self, n: isize) -> Self { if n == 1 { Self { x: self.x % MOD } } else if n % 2 == 1 { Self {x: (self.x * self.pow(n - 1).x) % MOD } } else { Self { x: self.pow(n / 2).x.pow(2) % MOD } } } } 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 mut ans = Modint::new(0); if a == b { ans = Modint::new(n as isize - 1) * Modint::new(n as isize - 2) * Modint::new(fac(n as isize - 3)); } else { ans = Modint::new(n as isize - 2) * Modint::new(n as isize - 3) * Modint::new(fac(n as isize - 2)) + Modint::new(2) * Modint::new(n as isize - 2) * Modint::new(fac(n as isize - 2)) + Modint::new(fac(n as isize - 2)); } println!("{}", ans); }