結果
問題 | No.347 微分と積分 |
ユーザー |
|
提出日時 | 2016-03-10 22:44:55 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 848 bytes |
コンパイル時間 | 12,346 ms |
コンパイル使用メモリ | 402,040 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 17:45:33 |
合計ジャッジ時間 | 13,433 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
コンパイルメッセージ
warning: unused import: `std::cmp::*` --> src/main.rs:1:5 | 1 | use std::cmp::*; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unnecessary parentheses around `if` condition --> src/main.rs:17:8 | 17 | if (a == -1.0) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 17 - if (a == -1.0) { 17 + if a == -1.0 { | warning: unused variable: `n` --> src/main.rs:28:9 | 28 | let n: i32 = parse(&getline().trim()); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
use std::cmp::*; use std::ops::Add; fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } fn parse<T : std::str::FromStr>(s : &str) -> T { match s.parse::<T>() { Ok(t) => t, _ => panic!(), } } fn integral(a: f64, b: f64) -> f64 { if (a == -1.0) { return b.ln(); } else { return b.powf(a + 1.0) / (a + 1.0); } } fn differential(a: f64, b: f64) -> f64 { return b.powf(a - 1.0) * a; } fn main() { let n: i32 = parse(&getline().trim()); let b: f64 = parse(&getline().trim()); let a = getline().trim().split(" ").map(|x| parse(x)).collect::<Vec<f64>>(); println!("{}", a.iter().map(|x| differential(*x, b)).fold(0.0, Add::add)); println!("{}", a.iter().map(|x| integral(*x, b)).fold(0.0, Add::add)); }