結果

問題 No.44 DPなすごろく
ユーザー hitoyozakehitoyozake
提出日時 2018-05-03 17:33:58
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 3,728 ms
コンパイル使用メモリ 151,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 09:19:40
合計ジャッジ時間 3,709 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `x`
 --> 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)]` on by default

warning: value assigned to `r` is never read
  --> Main.rs:14:13
   |
14 |     let mut r:i64 = 0;
   |             ^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

warning: 2 warnings emitted

ソースコード

diff #

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