結果
| 問題 |
No.2299 Antitypoglycemia
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-12 23:06:29 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,172 bytes |
| コンパイル時間 | 10,873 ms |
| コンパイル使用メモリ | 396,904 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-28 19:46:42 |
| 合計ジャッジ時間 | 12,166 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 3 |
コンパイルメッセージ
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);
}