結果

問題 No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
ユーザー maimai
提出日時 2021-04-20 01:40:01
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 2,061 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 150,396 KB
実行使用メモリ 31,088 KB
最終ジャッジ日時 2023-09-17 08:35:36
合計ジャッジ時間 2,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 14 ms
7,964 KB
testcase_10 AC 42 ms
25,256 KB
testcase_11 AC 43 ms
26,284 KB
testcase_12 AC 45 ms
27,664 KB
testcase_13 AC 45 ms
28,312 KB
testcase_14 AC 46 ms
28,992 KB
testcase_15 AC 48 ms
28,192 KB
testcase_16 AC 53 ms
31,088 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 => i32 * n);
    let total = aa.iter().fold(0 as i64, |s, e| s + *e as i64);
    println!("{}", total);
}
0