結果
| 問題 |
No.44 DPなすごろく
|
| ユーザー |
hitoyozake
|
| 提出日時 | 2018-05-03 17:33:58 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 714 bytes |
| コンパイル時間 | 14,241 ms |
| コンパイル使用メモリ | 374,856 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 00:44:54 |
| 合計ジャッジ時間 | 15,356 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 |
コンパイルメッセージ
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)]` on by default warning: value assigned to `r` is never read --> src/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
ソースコード
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);
}
hitoyozake