結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー koba-e964koba-e964
提出日時 2021-10-28 22:04:59
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,523 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 159,232 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-16 13:07:11
合計ジャッジ時間 5,354 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
testcase_107 -- -
testcase_108 -- -
testcase_109 -- -
testcase_110 -- -
testcase_111 -- -
testcase_112 -- -
testcase_113 -- -
testcase_114 -- -
testcase_115 -- -
testcase_116 -- -
testcase_117 -- -
testcase_118 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> main.rs:47:13
   |
47 |         let mut v = k as i64 * k as i64;
   |             ----^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#[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 k == 1 {
        return (if l < r { 1 } else { 0 }, 1);
    }
    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;
        }
        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);
}
0