結果

問題 No.347 微分と積分
ユーザー koba-e964koba-e964
提出日時 2016-03-10 22:44:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 848 bytes
コンパイル時間 5,184 ms
コンパイル使用メモリ 169,500 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:38:10
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::cmp::*`
 --> Main.rs:1:5
  |
1 | use std::cmp::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unnecessary parentheses around `if` condition
  --> 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`
  --> 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

warning: 3 warnings emitted

ソースコード

diff #

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));
}
0