結果

問題 No.44 DPなすごろく
ユーザー hitoyozake
提出日時 2018-05-03 17:33:58
言語 Rust
(1.99.0 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 0 ms / 5,000 ms
+ 800µs
コード長 714 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,831 ms
コンパイル使用メモリ 190,776 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-10-11 08:00:50
合計ジャッジ時間 5,968 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `x`
 --> src/main.rs:6:9
  |
6 |     let x = std::io::stdin().read_line(&mut buf).ok();
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: value assigned to `r` is never read
  --> src/main.rs:14:21
   |
14 |     let mut r:i64 = 0;
   |                     ^ this value is reassigned later and never used
...
18 |             r = number;
   |             ---------- `r` is overwritten here before the previous value is read
   |
   = note: `#[warn(unused_assignments)]` (part of `#[warn(unused)]`) on by default

ソースコード

diff #
raw source code

use std::collections::HashMap;

fn read_line()->String{
    let mut buf = String::new();

    let x = std::io::stdin().read_line(&mut buf).ok();
    
    buf
}


fn fibo(n:i64, map:&mut HashMap<i64, i64>)->i64
{
    let mut r:i64 = 0;
    match map.get(&n)
    {
        Some(&number) => {
            r = number;
        },
        _ => { 
            let num = fibo(n-1, map) + fibo(n-2, map);
            map.insert(n, num);
            r = num;
        },
    }
    r   
}

fn main() {
    let mut map:HashMap<i64, i64> = HashMap::new();

    let n = read_line().trim().parse::<i64>().unwrap();

    map.insert(1, 1);
    map.insert(2,1);

    let num = fibo(n+1, &mut map);

    println!("{}", num);


    
}
0