結果
| 問題 | No.3549 SigMax Digits (Judge ver.) |
| コンテスト | |
| ユーザー |
urectanc
|
| 提出日時 | 2026-05-22 23:28:41 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 228 ms / 3,000 ms |
| コード長 | 1,476 bytes |
| 記録 | |
| コンパイル時間 | 13,816 ms |
| コンパイル使用メモリ | 193,104 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-22 23:28:59 |
| 合計ジャッジ時間 | 5,354 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
use itertools::Itertools;
use proconio::{fastout, input};
#[fastout]
fn main() {
input! { t: usize }
for _ in 0..t {
input! { l: usize, r: usize }
let ans = solve(r) - solve(l - 1);
println!("{ans}");
}
}
fn solve(n: usize) -> usize {
let digits = n
.to_string()
.bytes()
.map(|b| (b - b'0') as usize)
.collect_vec();
let mut dp = [[0usize; 2]; 10];
dp[0][0] = 1;
for &d in &digits {
let mut ndp = [[0usize; 2]; 10];
for max in 0..10 {
for less in 0..2 {
if dp[max][less] == 0 {
continue;
}
for i in 0..10 {
if less == 0 && d < i {
break;
}
let nless = less | (i < d) as usize;
let nmax = max.max(i);
debug!(d, max, less, i, nless, nmax);
ndp[nmax][nless] += dp[max][less];
}
}
}
dp = ndp;
}
let mut ans = 0;
for max in 0..10 {
for less in 0..2 {
ans += max * dp[max][less];
}
}
ans
}
#[macro_export]
macro_rules! debug {
($($a:expr),* $(,)?) => {
#[cfg(debug_assertions)]
{
eprint!("{}:{}: ", file!(), line!());
eprintln!(concat!($(stringify!($a), " = \x1b[31m{:?}\x1b[m, "),*), $(&$a),*);
}
};
}
urectanc