結果
問題 | No.260 世界のなんとか3 |
ユーザー | ntk-ta01 |
提出日時 | 2021-07-05 16:13:27 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 253 ms / 2,000 ms |
コード長 | 4,220 bytes |
コンパイル時間 | 13,513 ms |
コンパイル使用メモリ | 390,428 KB |
実行使用メモリ | 23,680 KB |
最終ジャッジ日時 | 2024-07-01 11:59:38 |
合計ジャッジ時間 | 17,525 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 206 ms
23,680 KB |
testcase_04 | AC | 206 ms
23,680 KB |
testcase_05 | AC | 37 ms
6,940 KB |
testcase_06 | AC | 25 ms
6,940 KB |
testcase_07 | AC | 137 ms
16,640 KB |
testcase_08 | AC | 93 ms
12,032 KB |
testcase_09 | AC | 52 ms
7,424 KB |
testcase_10 | AC | 152 ms
18,560 KB |
testcase_11 | AC | 146 ms
17,536 KB |
testcase_12 | AC | 82 ms
11,136 KB |
testcase_13 | AC | 25 ms
6,944 KB |
testcase_14 | AC | 132 ms
16,000 KB |
testcase_15 | AC | 34 ms
6,940 KB |
testcase_16 | AC | 112 ms
14,208 KB |
testcase_17 | AC | 90 ms
11,520 KB |
testcase_18 | AC | 88 ms
11,008 KB |
testcase_19 | AC | 113 ms
14,080 KB |
testcase_20 | AC | 80 ms
10,496 KB |
testcase_21 | AC | 67 ms
9,472 KB |
testcase_22 | AC | 128 ms
15,872 KB |
testcase_23 | AC | 13 ms
6,940 KB |
testcase_24 | AC | 96 ms
12,672 KB |
testcase_25 | AC | 119 ms
12,800 KB |
testcase_26 | AC | 75 ms
12,800 KB |
testcase_27 | AC | 1 ms
6,940 KB |
testcase_28 | AC | 158 ms
23,680 KB |
testcase_29 | AC | 253 ms
23,552 KB |
ソースコード
macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } fn main() { input! { a: String, b: String, } const MOD: i32 = 1_000_000_007; let mut ds = vec![]; for c in b.chars() { let n = c as i32 - 48; ds.push(n); } let mut dp1 = vec![vec![vec![vec![vec![0; 8]; 3]; 2]; 2]; ds.len() + 1]; // dp1[i][is_less][has_3][mod3][mod8] dp1[0][0][0][0][0] = 1; for i in 0..ds.len() { for j in 0..=1 { for k in 0..=1 { for m in 0..3 { for n in 0..8 { let lim = if j == 1 { 9 } else { ds[i] }; for d in 0..=lim { let is_less: usize = if j == 1 || d < lim { 1 } else { 0 }; let has_3: usize = if k == 1 || d == 3 { 1 } else { 0 }; let mod_3: usize = (m + d as usize) % 3; let mod_8: usize = (n * 10 + d as usize) % 8; dp1[i + 1][is_less][has_3][mod_3][mod_8] += dp1[i][j][k][m][n]; dp1[i + 1][is_less][has_3][mod_3][mod_8] %= MOD; } } } } } } let mut answer = 0; for d in dp1[ds.len()].iter() { for k in 0..=1 { for m in 0..=2 { for n in 0..8 { if (k == 1 || m == 0) && n != 0 { answer += d[k][m][n]; answer %= MOD; } } } } } let mut ds = vec![]; for c in a.chars() { let n = c as i32 - 48; ds.push(n); } let mut dp2 = vec![vec![vec![vec![vec![0; 8]; 3]; 2]; 2]; ds.len() + 1]; // dp2[i][is_less][has_3][mod3][mod8] dp2[0][0][0][0][0] = 1; for i in 0..ds.len() { for j in 0..=1 { for k in 0..=1 { for m in 0..3 { for n in 0..8 { let lim = if j == 1 { 9 } else { ds[i] }; for d in 0..=lim { let is_less: usize = if j == 1 || d < lim { 1 } else { 0 }; let has_3: usize = if k == 1 || d == 3 { 1 } else { 0 }; let mod_3: usize = (m + d as usize) % 3; let mod_8: usize = (n * 10 + d as usize) % 8; dp2[i + 1][is_less][has_3][mod_3][mod_8] += dp2[i][j][k][m][n]; dp2[i + 1][is_less][has_3][mod_3][mod_8] %= MOD; } } } } } } for k in 0..=1 { for m in 0..=2 { for n in 0..8 { if (k == 1 || m == 0) && n != 0 { answer -= dp2[ds.len()][1][k][m][n]; answer += MOD; answer %= MOD; } } } } println!("{}", answer); }