結果
問題 | No.1271 初めての級数 |
ユーザー |
|
提出日時 | 2020-10-30 22:00:05 |
言語 | Rust (1.59.0) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 2,107 bytes |
コンパイル時間 | 843 ms |
使用メモリ | 6,324 KB |
最終ジャッジ日時 | 2023-02-21 12:32:14 |
合計ジャッジ時間 | 4,168 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 159 ms
6,176 KB |
testcase_01 | AC | 160 ms
6,188 KB |
testcase_02 | AC | 159 ms
6,324 KB |
testcase_03 | AC | 160 ms
6,204 KB |
testcase_04 | AC | 159 ms
6,192 KB |
testcase_05 | AC | 159 ms
6,172 KB |
testcase_06 | AC | 160 ms
6,192 KB |
testcase_07 | AC | 160 ms
6,180 KB |
testcase_08 | AC | 159 ms
6,280 KB |
testcase_09 | AC | 159 ms
6,284 KB |
testcase_10 | AC | 160 ms
6,256 KB |
testcase_11 | AC | 159 ms
6,200 KB |
testcase_12 | AC | 159 ms
6,268 KB |
ソースコード
use std::io::{self, Write}; use std::{fmt, ops, str}; macro_rules! read { ( $t:ty ) => {{ let mut input = String::new(); io::stdin().read_line(&mut input).unwrap(); input.trim_end().parse::<$t>().ok().unwrap() }}; ( $( $t:ty ),* ) => {{ let mut input = String::new(); io::stdin().read_line(&mut input).unwrap(); let mut iter = input.split_whitespace(); ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* ) }}; } struct IoStr(Vec<char>); impl str::FromStr for IoStr { type Err = (); fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(IoStr(s.chars().collect())) } } impl fmt::Display for IoStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0.iter().collect::<String>()) } } #[derive(Clone)] struct IoVec<T>(Vec<T>); impl<T: str::FromStr> str::FromStr for IoVec<T> { type Err = T::Err; fn from_str(s: &str) -> Result<Self, Self::Err> { let iter = s.split_whitespace(); Ok(IoVec(iter.map(|x| x.parse()).collect::<Result<_, _>>()?)) } } impl<T: fmt::Display> fmt::Display for IoVec<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0.iter().map(|x| x.to_string()) .collect::<Vec<_>>().join(" ") ) } } impl<T> ops::Index<usize> for IoVec<T> { type Output = T; fn index(&self, i: usize) -> &Self::Output { self.0.get(i - 1).unwrap() } } impl<T> ops::IndexMut<usize> for IoVec<T> { fn index_mut(&mut self, i: usize) -> &mut Self::Output { self.0.get_mut(i - 1).unwrap() } } const EPS: f64 = 1e-16; fn solve(writer: &mut io::BufWriter<io::StdoutLock>) { let k = read!(f64); let mut ans = 0.0; for n in (1..).map(|n| n as f64) { let a = 1.0 / (n * (n + k)); if a < EPS { break; } ans += a; } writeln!(writer, "{:.10}", ans).ok(); } fn main() { let stdout = io::stdout(); let mut writer = io::BufWriter::new(stdout.lock()); solve(&mut writer); }