結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー |
|
提出日時 | 2021-10-28 22:08:26 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,612 bytes |
コンパイル時間 | 13,278 ms |
コンパイル使用メモリ | 377,776 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-07 08:10:44 |
合計ジャッジ時間 | 14,328 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 2 |
other | AC * 2 WA * 113 |
ソースコード
#[allow(unused_imports)]use std::cmp::*;#[allow(unused_imports)]use std::collections::*;use std::io::Read;#[allow(dead_code)]fn getline() -> String {let mut ret = String::new();std::io::stdin().read_line(&mut ret).ok().unwrap();ret}fn get_word() -> String {let stdin = std::io::stdin();let mut stdin=stdin.lock();let mut u8b: [u8; 1] = [0];loop {let mut buf: Vec<u8> = Vec::with_capacity(16);loop {let res = stdin.read(&mut u8b);if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {break;} else {buf.push(u8b[0]);}}if buf.len() >= 1 {let ret = String::from_utf8(buf).unwrap();return ret;}}}#[allow(dead_code)]fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }const MOD: i64 = 1_000_000_007;fn dfs(k: usize, l: i64, r: i64, len: &[i64]) -> (i64, i64) {if l == r {return (0, 1);}if k == 1 {return (1, 1);}assert!(r <= len[k]);assert!(l <= r);if (l, r) == (0, len[k]) {let mut a = 0;let mut b = 1;let mut v = k as i64 * k as i64;while v > 0 {let mut r = v % 10;a += r;if r == 0 { r = 10; }b = b * r % MOD;v /= 10;}let (c, d) = dfs(k - 1, 0, len[k - 1], len);a += 2 * c;b = b * d % MOD * d % MOD;return (a, b);}let mut a = 0;let mut b = 1;let mid1 = len[k - 1];let mid2 = len[k] - len[k - 1];if l < mid1 {let (c, d) = dfs(k - 1, l, min(r, mid1), &len);a += c;b = b * d % MOD;}if l < mid2 && r < mid1 {let s: Vec<_> = format!("{}", k * k).bytes().collect();for i in max(l, mid1) - mid1..min(r, mid2) - mid1 {let v = s[i as usize] as i64;a += r;let v = if v == 0 { 10 } else { v };b = b % v % MOD;}}if r > mid2 {let (c, d) = dfs(k - 1, max(l, mid2) - mid2, r - mid2, &len);a += c;b = b * d % MOD;}(a, b)}fn main() {let k: usize = get();let l: i64 = get();let r: i64 = get();let mut len = vec![0; 62];len[1] = 1;for i in 2..62 {len[i] = len[i - 1] * 2 + format!("{}", i * i).len() as i64;}let k = min(k, 61);if r > len[k] {println!("-1");return;}let (a, b) = dfs(k, l - 1, r, &len);println!("{} {}", a, b);}