結果
問題 | No.2783 4-33 Easy |
ユーザー | Yukino DX. |
提出日時 | 2024-06-14 22:13:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 501 ms / 2,000 ms |
コード長 | 4,590 bytes |
コンパイル時間 | 14,287 ms |
コンパイル使用メモリ | 402,364 KB |
実行使用メモリ | 192,768 KB |
最終ジャッジ日時 | 2024-06-14 22:13:45 |
合計ジャッジ時間 | 27,479 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,816 KB |
testcase_01 | AC | 20 ms
9,728 KB |
testcase_02 | AC | 14 ms
6,940 KB |
testcase_03 | AC | 10 ms
6,940 KB |
testcase_04 | AC | 364 ms
152,064 KB |
testcase_05 | AC | 470 ms
192,640 KB |
testcase_06 | AC | 470 ms
192,640 KB |
testcase_07 | AC | 470 ms
192,640 KB |
testcase_08 | AC | 499 ms
192,768 KB |
testcase_09 | AC | 469 ms
192,640 KB |
testcase_10 | AC | 469 ms
192,640 KB |
testcase_11 | AC | 468 ms
192,768 KB |
testcase_12 | AC | 479 ms
192,768 KB |
testcase_13 | AC | 501 ms
192,640 KB |
testcase_14 | AC | 470 ms
192,768 KB |
testcase_15 | AC | 469 ms
192,768 KB |
testcase_16 | AC | 474 ms
192,640 KB |
testcase_17 | AC | 468 ms
192,768 KB |
testcase_18 | AC | 494 ms
192,640 KB |
testcase_19 | AC | 472 ms
192,640 KB |
testcase_20 | AC | 473 ms
192,640 KB |
testcase_21 | AC | 499 ms
192,640 KB |
testcase_22 | AC | 475 ms
192,768 KB |
testcase_23 | AC | 480 ms
192,768 KB |
testcase_24 | AC | 474 ms
192,640 KB |
testcase_25 | AC | 471 ms
192,768 KB |
testcase_26 | AC | 472 ms
192,768 KB |
testcase_27 | AC | 471 ms
192,768 KB |
testcase_28 | AC | 472 ms
192,768 KB |
ソースコード
use proconio::input; fn main() { input! { n:usize, a:[usize;n], b:[String;n], } let mut dp = vec![vec![vec![vec![vec![ModInt::<MOD>::new(0); 2]; 34]; 5]; 10]; n + 1]; dp[0][0][0][0][0] = ModInt::new(1); for i in 0..n { for j in 0..10 { for u in 0..5 { for d in 0..34 { for k in 0..2 { dp[i + 1][j][u][d][k] = dp[i + 1][j][u][d][k] + dp[i][j][u][d][k]; if j >= 9 { continue; } if b[i].parse::<usize>().is_ok() { let di = b[i].parse::<usize>().unwrap(); if u + a[i] > 4 || d + di > 33 { continue; } dp[i + 1][j + 1][u + a[i]][d + di][k] = dp[i + 1][j + 1][u + a[i]][d + di][k] + dp[i][j][u][d][k]; } if b[i].starts_with('X') && k == 0 { if u + a[i] > 4 { continue; } dp[i + 1][j + 1][u + a[i]][d][1] = dp[i + 1][j + 1][u + a[i]][d][1] + dp[i][j][u][d][k]; } } } } } } let ans = dp[n][9][4][33][1]; println!("{}", ans); } const MOD: usize = 998244353; use modint::*; mod modint { use std::fmt; use std::ops; #[derive(Copy, Clone, PartialEq, Eq)] pub struct ModInt<const MOD: usize> { pub val: usize, } impl<const MOD: usize> ModInt<MOD> { pub fn new(val: usize) -> Self { Self { val: val % MOD } } pub fn pow(mut self, mut e: usize) -> Self { let mut res = Self::new(1); while 0 < e { if e & 1 != 0 { res *= self; } self *= self; e >>= 1; } res } } impl<const MOD: usize> From<usize> for ModInt<MOD> { fn from(value: usize) -> Self { Self { val: value % MOD } } } impl<const MOD: usize> fmt::Display for ModInt<MOD> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.val) } } impl<const MOD: usize> fmt::Debug for ModInt<MOD> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.val) } } impl<const MOD: usize> ops::Neg for ModInt<MOD> { type Output = Self; fn neg(self) -> Self::Output { Self { val: (MOD - self.val) % MOD, } } } impl<const MOD: usize> ops::Add for ModInt<MOD> { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self { val: (self.val + rhs.val) % MOD, } } } impl<const MOD: usize> ops::AddAssign for ModInt<MOD> { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; } } impl<const MOD: usize> ops::Mul for ModInt<MOD> { type Output = Self; fn mul(self, rhs: Self) -> Self::Output { Self { val: self.val * rhs.val % MOD, } } } impl<const MOD: usize> ops::MulAssign for ModInt<MOD> { fn mul_assign(&mut self, rhs: Self) { *self = *self * rhs; } } impl<const MOD: usize> ops::Sub for ModInt<MOD> { type Output = Self; fn sub(mut self, rhs: Self) -> Self::Output { if self.val < rhs.val { self.val += MOD; } Self { val: (self.val - rhs.val) % MOD, } } } impl<const MOD: usize> ops::SubAssign for ModInt<MOD> { fn sub_assign(&mut self, rhs: Self) { if self.val < rhs.val { self.val += MOD; } *self = *self - rhs; } } impl<const MOD: usize> ops::Div for ModInt<MOD> { type Output = Self; fn div(self, rhs: Self) -> Self { assert!(rhs.val != 0); self * rhs.pow(MOD - 2) } } impl<const MOD: usize> ops::DivAssign for ModInt<MOD> { fn div_assign(&mut self, rhs: Self) { *self = *self / rhs } } }