結果
| 問題 | No.189 SUPER HAPPY DAY |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-21 23:15:39 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 5,000 ms |
| コード長 | 4,090 bytes |
| コンパイル時間 | 13,769 ms |
| コンパイル使用メモリ | 379,292 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 15:41:35 |
| 合計ジャッジ時間 | 14,274 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#![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);
}