結果
問題 |
No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
|
ユーザー |
|
提出日時 | 2021-04-20 01:41:32 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 2,037 bytes |
コンパイル時間 | 14,536 ms |
コンパイル使用メモリ | 390,092 KB |
実行使用メモリ | 33,104 KB |
最終ジャッジ日時 | 2024-07-04 05:14:28 |
合計ジャッジ時間 | 13,134 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
use std::collections::*; struct Scanner<R: std::io::BufRead> { stack: VecDeque<Vec<String>>, input: R, } impl<R: std::io::BufRead> Scanner<R> { fn new(input: R) -> Self { Self { stack: VecDeque::<Vec<String>>::new(), input: input, } } fn take(&mut self) -> Option<String> { while let Some(s) = self.stack.front_mut() { if let Some(t) = s.pop() { return Some(t); } self.stack.pop_front(); } self.enqueue_line(); if !self.stack.is_empty() { return self.take(); } None } fn enqueue(&mut self, t: String) { self.stack.push_back( t.trim() .split_ascii_whitespace() .map(|s| s.to_owned()) .rev() .collect(), ) } #[allow(unused)] fn enqueue_line(&mut self) { let mut t = String::new(); self.input.read_line(&mut t).ok(); self.enqueue(t); } #[allow(unused)] fn enqueue_to_end(&mut self) { let mut t = String::new(); self.input.read_to_string(&mut t).ok(); self.enqueue(t); } } #[allow(unused)] macro_rules! scan { ($io:expr => $t:ty) => { $io.take().unwrap().parse::<$t>().unwrap() }; ($io:expr => $t:tt * $n:expr) => ((0..$n).map(|_| scan!($io => $t)).collect::<Vec<_>>()); ($io:expr => $($t:tt),*) => (($(scan!($io => $t)),*)); } macro_rules! scan { ($io:expr => $t:ty) => { $io.take().unwrap().parse::<$t>().unwrap() }; ($io:expr => $t:tt * $n:expr) => ((0..$n).map(|_| scan!($io => $t)).collect::<Vec<_>>()); ($io:expr => $($t:tt),*) => (($(scan!($io => $t)),*)); } fn main() { solve(Scanner::<std::io::StdinLock>::new(std::io::stdin().lock())) } fn solve<R: std::io::BufRead>(mut cin: Scanner<R>) { let n = scan!(cin => i32); let aa = scan!(cin => i64 * n); let total = aa.iter().sum::<i64>(); println!("{}", total); }