Submission #71155691
Source Code Expand
use proconio::{input, marker::Chars};
type Mint = ac_library::ModInt998244353;
fn combination(n: usize, r: usize, fact: &[Mint], fact_inv: &[Mint]) -> Mint {
fact[n] * fact_inv[r] * fact_inv[n - r]
}
fn ctoi(c: char) -> usize {
(c as u8 - '0' as u8) as usize
}
fn main() {
input! {
s: Chars,
}
let n = s.len();
let mut fact = vec![Mint::new(1); n + 1];
for i in 2..=n {
fact[i] = fact[i - 1] * i;
}
let mut fact_inv = vec![Mint::new(1); n + 1];
for i in 0..=n {
fact_inv[i] = fact[i].inv();
}
let mut cum = vec![vec![0usize; n + 1]; 10]; // 最大10桁
for (i, &c) in s.iter().enumerate() {
let j = ctoi(c);
cum[j][i + 1] = 1;
}
for j in 0..10 {
for i in 0..n {
cum[j][i + 1] += cum[j][i];
}
}
let mut result = Mint::new(0);
for (i, &c) in s.iter().enumerate() {
let j = ctoi(c);
if j == 9 || cum[j][i] == cum[j][i + 1] {
continue;
}
let x0 = cum[j][i + 1];
let x1 = cum[j + 1][n] - cum[j + 1][i + 1];
for r in 1..=x0.min(x1) {
result +=
combination(x0 - 1, r - 1, &fact, &fact_inv) * combination(x1, r, &fact, &fact_inv);
}
}
println!("{result}");
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - 1122 Subsequence 2 |
| User | hossie |
| Language | Rust (rustc 1.89.0) |
| Score | 0 |
| Code Size | 1306 Byte |
| Status | TLE |
| Exec Time | > 2000 ms |
| Memory | 92896 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 1824 KiB |
| 00_sample_01.txt | AC | 0 ms | 2048 KiB |
| 00_sample_02.txt | AC | 0 ms | 1992 KiB |
| 01_random_00.txt | AC | 0 ms | 1932 KiB |
| 01_random_01.txt | AC | 155 ms | 92816 KiB |
| 01_random_02.txt | TLE | > 2000 ms | 92768 KiB |
| 01_random_03.txt | TLE | > 2000 ms | 92896 KiB |
| 01_random_04.txt | TLE | > 2000 ms | 92796 KiB |
| 01_random_05.txt | TLE | > 2000 ms | 92800 KiB |
| 01_random_06.txt | TLE | > 2000 ms | 92668 KiB |
| 01_random_07.txt | TLE | > 2000 ms | 92772 KiB |
| 01_random_08.txt | TLE | > 2000 ms | 45800 KiB |
| 01_random_09.txt | TLE | > 2000 ms | 92788 KiB |
| 01_random_10.txt | TLE | > 2000 ms | 39712 KiB |
| 01_random_11.txt | TLE | > 2000 ms | 92744 KiB |
| 01_random_12.txt | AC | 21 ms | 3104 KiB |
| 01_random_13.txt | TLE | > 2000 ms | 92772 KiB |
| 01_random_14.txt | AC | 1491 ms | 13152 KiB |
| 01_random_15.txt | TLE | > 2000 ms | 92840 KiB |
| 01_random_16.txt | TLE | > 2000 ms | 20968 KiB |
| 01_random_17.txt | TLE | > 2000 ms | 92768 KiB |
| 01_random_18.txt | TLE | > 2000 ms | 92832 KiB |
| 01_random_19.txt | AC | 156 ms | 92840 KiB |
| 01_random_20.txt | AC | 154 ms | 92764 KiB |
| 01_random_21.txt | AC | 158 ms | 92860 KiB |
| 01_random_22.txt | TLE | > 2000 ms | 13928 KiB |
| 01_random_23.txt | TLE | > 2000 ms | 14040 KiB |