Submission #54403266


Source Code Expand

#![allow(unused)]

fn main() {
    let n = read::<u64>();
    let m = 998244353;
    let d = n.to_string().chars().collect::<Vec<char>>().len();
    let b = 10u64.pow(d as u32) % m;

    let mat = vec![vec![b, 1], vec![0, 1]];
    let mat = matpow(&mat, n, m);
    let ans = mat[0][1] * (n % m) % m;
    println!("{}", ans);
}

type Mat = Vec<Vec<u64>>;

fn matmul(a: &Mat, b: &Mat, m: u64) -> Mat {
    let (h, w) = (a.len(), b[0].len());
    let mut res = vec![vec![0; w]; h];
    for r in 0..h {
        for c in 0..w {
            for k in 0..b.len() {
                res[r][c] += (a[r][k] * b[k][c]) % m;
                res[r][c] %= m;
            }
        }
    }
    res
}

fn matpow(mat: &Mat, mut exp: u64, m: u64) -> Mat {
    let n = mat.len();
    let mut base = mat.clone();
    let mut ans = vec![vec![0; n]; n];
    for i in 0..n {
        ans[i][i] = 1;
    }
    while exp > 0 {
        if exp & 1 == 1 {
            ans = matmul(&ans, &base, m);
        }
        base = matmul(&base, &base, m);
        exp >>= 1;
    }
    ans
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn readv<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_ascii_whitespace()
        .map(|t| t.parse().ok().unwrap())
        .collect()
}

fn reads() -> Vec<char> {
    read::<String>().chars().collect()
}

fn mapv<T, S, F: Fn(&T) -> S>(arr: &Vec<T>, f: F) -> Vec<S> {
    arr.iter().map(f).collect()
}

fn join<T: ToString>(arr: &[T], sep: &str) -> String {
    arr.iter()
        .map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(sep)
}

Submission Info

Submission Time
Task D - 88888888
User amoshuangyc
Language Rust (rustc 1.70.0)
Score 350
Code Size 1766 Byte
Status AC
Exec Time 1 ms
Memory 2072 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 28
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 1928 KiB
example_01.txt AC 1 ms 1844 KiB
example_02.txt AC 0 ms 1920 KiB
hand_00.txt AC 0 ms 1888 KiB
hand_01.txt AC 0 ms 1912 KiB
hand_02.txt AC 0 ms 1960 KiB
hand_03.txt AC 1 ms 1720 KiB
hand_04.txt AC 1 ms 1908 KiB
hand_05.txt AC 0 ms 1888 KiB
hand_06.txt AC 1 ms 1924 KiB
hand_07.txt AC 1 ms 1920 KiB
hand_08.txt AC 1 ms 1780 KiB
hand_09.txt AC 1 ms 1968 KiB
random_00.txt AC 1 ms 1788 KiB
random_01.txt AC 0 ms 1996 KiB
random_02.txt AC 1 ms 1992 KiB
random_03.txt AC 0 ms 1848 KiB
random_04.txt AC 1 ms 1860 KiB
random_05.txt AC 1 ms 2072 KiB
random_06.txt AC 1 ms 1896 KiB
random_07.txt AC 0 ms 1904 KiB
random_08.txt AC 1 ms 1936 KiB
random_09.txt AC 1 ms 2064 KiB
random_10.txt AC 1 ms 2060 KiB
random_11.txt AC 0 ms 1964 KiB
random_12.txt AC 0 ms 1788 KiB
random_13.txt AC 1 ms 1932 KiB
random_14.txt AC 0 ms 1956 KiB