Submission #29325351


Source Code Expand

use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize,
        a: [usize; n - 1],
        m: usize,
        b: [Usize1; m],
    };

    let c = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, &i| {
            *acc += i;
            Some(*acc)
        }))
        .collect::<Vec<usize>>();

    let mut ans = 0_usize;
    let mut prev = b[0];
    for b_i in b.into_iter().skip(1) {
        let (l, r) = if b_i < prev { (b_i, prev) } else { (prev, b_i) };
        ans += c[r] - c[l];
        prev = b_i;
    }

    println!("{}", ans);
}

Submission Info

Submission Time
Task 040 - Travel
User bouzuya
Language Rust (1.42.0)
Score 1000
Code Size 574 Byte
Status AC
Exec Time 32 ms
Memory 9616 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 1
AC × 16
Set Name Test Cases
Sample sample-01.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, sample-01.txt
Case Name Status Exec Time Memory
01-01.txt AC 32 ms 8544 KiB
01-02.txt AC 25 ms 8792 KiB
01-03.txt AC 8 ms 3712 KiB
01-04.txt AC 26 ms 9616 KiB
01-05.txt AC 24 ms 9576 KiB
01-06.txt AC 25 ms 9496 KiB
01-07.txt AC 11 ms 3844 KiB
01-08.txt AC 26 ms 9184 KiB
01-09.txt AC 23 ms 9456 KiB
01-10.txt AC 14 ms 4492 KiB
01-11.txt AC 17 ms 5824 KiB
01-12.txt AC 22 ms 7748 KiB
01-13.txt AC 13 ms 3668 KiB
01-14.txt AC 29 ms 9528 KiB
01-15.txt AC 24 ms 9560 KiB
sample-01.txt AC 1 ms 1952 KiB