Submission #15875206


Source Code Expand

Copy
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let s = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, &a_i| {
            *acc += a_i;
            Some(*acc)
        }))
        .collect::<Vec<i64>>();
    let mut m = std::collections::BTreeMap::new();
    for &s_i in s.iter() {
        let entry = m.entry(s_i).or_insert(0);
        *entry += 1;
    }
    let ans = m
        .values()
        .filter(|&&v| v >= 2)
        .map(|&v| v * (v - 1) / 2)
        .sum::<i64>();
    println!("{}", ans);
}

Submission Info

Submission Time
Task A - Zero-Sum Ranges
User bouzuya
Language Rust (1.42.0)
Score 200
Code Size 563 Byte
Status AC
Exec Time 56 ms
Memory 13044 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt
Case Name Status Exec Time Memory
sample_01.txt AC 10 ms 2060 KB
sample_02.txt AC 2 ms 2040 KB
sample_03.txt AC 1 ms 2088 KB
subtask_1_01.txt AC 2 ms 2032 KB
subtask_1_02.txt AC 1 ms 2100 KB
subtask_1_03.txt AC 29 ms 5836 KB
subtask_1_04.txt AC 12 ms 2808 KB
subtask_1_05.txt AC 15 ms 3700 KB
subtask_1_06.txt AC 53 ms 13044 KB
subtask_1_07.txt AC 27 ms 5776 KB
subtask_1_08.txt AC 24 ms 5584 KB
subtask_1_09.txt AC 19 ms 5644 KB
subtask_1_10.txt AC 56 ms 10720 KB
subtask_1_11.txt AC 35 ms 5996 KB
subtask_1_12.txt AC 36 ms 6148 KB
subtask_1_13.txt AC 55 ms 10788 KB
subtask_1_14.txt AC 34 ms 6160 KB
subtask_1_15.txt AC 33 ms 6092 KB