結果

問題 No.189 SUPER HAPPY DAY
ユーザー kaeru82433413kaeru82433413
提出日時 2021-12-21 23:15:39
言語 Rust
(1.77.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 4,090 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 158,264 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 19:56:13
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 14 ms
4,352 KB
testcase_15 AC 17 ms
4,348 KB
testcase_16 AC 20 ms
4,348 KB
testcase_17 AC 19 ms
4,352 KB
testcase_18 AC 16 ms
4,352 KB
testcase_19 AC 22 ms
4,348 KB
testcase_20 AC 7 ms
4,348 KB
testcase_21 AC 6 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 16 ms
4,352 KB
testcase_24 AC 15 ms
4,352 KB
testcase_25 AC 30 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
use std::io::Read;
use std::cmp;
use std::collections::{HashSet, HashMap, VecDeque as Deque, BTreeSet};
use std::f64::consts::PI;
type int = usize;
type float = f64;
const TAU: float = PI*2.;
const M1: int = 1_000_000_007;
const M9: int = 998_244_353;
const INF: int = 9223372036854775807;
fn yn(value: bool) {println!("{}", if value {"Yes"} else {"No"})}
fn repeat<T>(vector: Vec<T>, n: int) -> Vec<Vec<T>> where 
T: Clone{
    let mut res = vec![];
    for _ in 0..n {
        res.push(vec![]);
        for value in vector.iter() {
            res.last_mut().unwrap().push(value.clone());
        }
    }
    res
}
fn flog(mut n: int, base: int) -> int {
    let mut res = 0;
    while n>=base {
        n /= base;
        res += 1;
    }
    res
}
fn pow(base: int, exp: int) -> int {
    powmod(base, exp, INF)
}
fn powmod(base: int, exp: int, modulo: int) -> int {
    if exp == 0 {
        return 1 % modulo
    }
    let mut res = powmod(base, exp/2, modulo).pow(2)%modulo;
    if exp%2==1 {
        res *= base;
        res %= modulo;
    }
    res
}
fn get_digits(mut value: int) -> Vec<int> {
    let mut res = Vec::new();
    while value > 0 {
        res.push(value%10);
        value /= 10;
    }
    res.into_iter().rev().collect()
}
fn get_bits(mut value: int ,size: int) -> Vec<int> {
    let mut res = Vec::new();
    for _ in 0..size {
        res.push(value%2);
        value >>= 1;
    }
    res
}
fn permutations(n: int, k: int) -> Vec<Vec<int>> {
    let mut res = Vec::new();
    let mut remain: BTreeSet<_> = (0..n).collect();
    let mut now = Vec::new();
    permutations_rec(&mut res, &mut now, &mut remain, k);
    res
}
fn permutations_rec(mut res: &mut Vec<Vec<usize>>, mut now: &mut Vec<int> ,mut remain: &mut BTreeSet::<int>, k: int) {
    if k == 0 {
        res.push(now.clone());
        return;
    }
    let copy = remain.clone();
    for i in copy {
        remain.remove(&i);
        now.push(i);
        permutations_rec(&mut res, &mut now, &mut remain, k-1);
        remain.insert(i);
        now.pop();
    }
}
fn bsearch(x: int, v: &[int]) -> usize {
    let (mut ok, mut ng) = (0, v.len());
    while ok+1<ng {
        let mid = ok+(ng-ok)/2;
        if v[mid] < x {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ng
}
fn inputl() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).unwrap();
    res.trim().to_string()
}
macro_rules! debug {($($a:expr),* $(,)*) => {#[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);};}


fn mods(n: Vec<int>) -> Vec<int> {
    let len = 9*n.len()+1;
    let mut dp = repeat(vec![0].repeat(len), 2);
    dp[0][0] = 1;
    for &d in n.iter() {
        let mut update = repeat(vec![0].repeat(len), 2);
        for l in 0..2 {
            for c in 0..10 {
                if l==0 && c>d {
                    continue;
                }
                for i in 0..len-c {
                    update[l | (c<d) as int][i+c] += dp[l][i];
                    update[l | (c<d) as int][i+c] %= 1000000009;
                }
            }
        }
        dp = update;
    }
    let mut res = vec![0].repeat(len);
    for row in dp.iter() {
        for (i, &value) in row.iter().enumerate() {
            res[i] += value;
        }
    }
    res
}

fn main() {
    let input = inputl();
    let mut input_itr = input.split_whitespace();
    let M: Vec<int> = input_itr.next().unwrap().chars().map(|c| c.to_string().parse().unwrap()).collect();
    let D: Vec<int> = input_itr.next().unwrap().chars().map(|c| c.to_string().parse().unwrap()).collect();
    
    let M: Vec<int> = M.iter().map(|c| c.to_string().parse().unwrap()).collect();
    let D: Vec<int> = D.iter().map(|c| c.to_string().parse().unwrap()).collect();
    let mut ans = 0;
    for (m, d) in mods(M).iter().zip(mods(D)).skip(1) {
        ans += m*d;
        ans %= 1000000009;
    }
    println!("{}", ans);
}
0