結果
| 問題 | No.1138 No Bingo! |
| ユーザー |
ikd
|
| 提出日時 | 2020-08-08 21:33:43 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 3,000 ms |
| コード長 | 5,608 bytes |
| コンパイル時間 | 10,679 ms |
| コンパイル使用メモリ | 403,620 KB |
| 実行使用メモリ | 8,264 KB |
| 最終ジャッジ日時 | 2025-03-16 15:13:53 |
| 合計ジャッジ時間 | 12,258 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
warning: unused imports: `AddAssign` and `Div`
--> src/main.rs:56:25
|
56 | use std::ops::{Add, AddAssign, Div, Mul, Rem, Sub};
| ^^^^^^^^^ ^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused variable: `i`
--> src/main.rs:216:9
|
216 | for i in 0..10 {
| ^ help: if this is intentional, prefix it with an underscore: `_i`
|
= note: `#[warn(unused_variables)]` on by default
warning: function `f` is never used
--> src/main.rs:187:4
|
187 | fn f(n: usize) -> i32 {
| ^
|
= note: `#[warn(dead_code)]` on by default
ソースコード
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
let mut next = || { iter.next().unwrap() };
input_inner!{next, $($r)*}
};
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes
.by_ref()
.map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}
macro_rules! input_inner {
($next:expr) => {};
($next:expr, ) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}
macro_rules! read_value {
($next:expr, ( $($t:tt),* )) => {
( $(read_value!($next, $t)),* )
};
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, usize1) => {
read_value!($next, usize) - 1
};
($next:expr, $t:ty) => {
$next().parse::<$t>().expect("Parse error")
};
}
mod mint {
use std::ops::{Add, AddAssign, Div, Mul, Rem, Sub};
#[derive(Copy, Clone)]
pub struct Mint<T> {
x: T,
mo: T,
}
impl<T> Mint<T>
where
T: Copy,
{
pub fn new(x: T, mo: T) -> Mint<T> {
Mint { x, mo }
}
}
impl<T> Mint<T>
where
T: Copy,
{
pub fn val(&self) -> T {
self.x
}
pub fn mo(&self) -> T {
self.mo
}
}
impl<T> Add<T> for Mint<T>
where
T: Copy,
T: Add<Output = T>,
T: Rem<Output = T>,
{
type Output = Mint<T>;
fn add(self, rhs: T) -> Mint<T> {
Mint::new((self.val() + rhs % self.mo()) % self.mo(), self.mo())
}
}
impl<T> Add<Mint<T>> for Mint<T>
where
T: Copy,
Mint<T>: Add<T, Output = Mint<T>>,
{
type Output = Mint<T>;
fn add(self, rhs: Mint<T>) -> Mint<T> {
self + rhs.val()
}
}
impl<T> Sub<T> for Mint<T>
where
T: Copy,
T: Add<Output = T>,
T: Sub<Output = T>,
T: Rem<Output = T>,
{
type Output = Mint<T>;
fn sub(self, rhs: T) -> Mint<T> {
Mint::new(
(self.val() + self.mo() - rhs % self.mo()) % self.mo(),
self.mo(),
)
}
}
impl<T> Sub<Mint<T>> for Mint<T>
where
T: Copy,
Mint<T>: Sub<T, Output = Mint<T>>,
{
type Output = Mint<T>;
fn sub(self, rhs: Mint<T>) -> Mint<T> {
self - rhs.val()
}
}
impl<T> Mul<T> for Mint<T>
where
T: Copy,
T: Mul<Output = T>,
T: Rem<Output = T>,
{
type Output = Mint<T>;
fn mul(self, rhs: T) -> Mint<T> {
Mint::new((self.val() * rhs % self.mo()) % self.mo(), self.mo())
}
}
impl<T> Mul<Mint<T>> for Mint<T>
where
T: Copy,
Mint<T>: Mul<T, Output = Mint<T>>,
{
type Output = Mint<T>;
fn mul(self, rhs: Mint<T>) -> Mint<T> {
self * rhs.val()
}
}
impl<T> std::fmt::Display for Mint<T>
where
T: Copy + std::fmt::Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.val())
}
}
}
use mint::Mint;
pub trait NextPermutation {
fn next_permutation(&mut self) -> bool;
}
impl<T: Ord> NextPermutation for [T] {
fn next_permutation(&mut self) -> bool {
if self.is_empty() {
return false;
}
let mut i = self.len() - 1;
while i > 0 && self[i - 1] >= self[i] {
i -= 1;
}
if i == 0 {
return false;
}
let mut j = self.len() - 1;
while self[i - 1] >= self[j] {
j -= 1;
}
self.swap(i - 1, j);
self[i..].reverse();
return true;
}
}
fn f(n: usize) -> i32 {
let mut v = (0..n).collect::<Vec<_>>();
let mut res = 0;
loop {
if v.iter().zip(0..n).all(|(&x, i)| x != i && x != n - i - 1) {
res += 1;
}
if !v.next_permutation() {
break;
}
}
res
}
fn main() {
input! {
n: usize,
}
let mo = 998244353;
let mut a = Mint::new(1, mo);
for i in 1..=n {
a = a * i;
}
let mut b = vec![Mint::new(0, mo); n + 2];
b[2] = Mint::new(1, mo);
for i in 3..=n {
b[i] = (b[i - 1] + b[i - 2]) * (i - 1);
}
let b = b[n];
for i in 0..10 {
// println!("{} {}", i, f(i));
// 0 1
// 1 0
// 2 0
// 3 0
// 4 4
// 5 16
// 6 80
// 7 672
// 8 4752
// 9 48768
// https://oeis.org/A003471
}
let mut c = vec![Mint::new(0, mo); n + 2];
c[0] = Mint::new(1, mo);
for i in 4..=n {
if i % 2 == 0 {
c[i] = c[i - 1] * (i - 1) + c[i - 4] * 2 * (i - 2);
} else {
c[i] = c[i - 1] * (i - 1) + c[i - 2] * 2 * (i - 1);
}
}
let c = c[n];
println!("{}", a - b * 2 + c);
}
ikd