Submission #8574431


Source Code Expand

Copy
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect(); 

    let mut ans: i64 = 1 << 29;
    let mut rui: Vec<i64> = vec![0; n+1];
    for i in 0..n {
        rui[i+1] = a[i] + rui[i];
    }

    for i in 0..n {
        let l = rui[i+1];
        let r = rui[n] - l;
        let d = if l < r {r-l} else {l-r};
        ans = std::cmp::min(ans, d);
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Submission Info

Submission Time
Task B - Iron Bar Cutting
User mds_boy
Language Rust (1.15.1)
Score 0
Code Size 802 Byte
Status WA
Exec Time 82 ms
Memory 8444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 200
Status
AC × 2
AC × 12
WA × 8
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
in01.txt AC 2 ms 4352 KB
in02.txt AC 2 ms 4352 KB
in03.txt AC 2 ms 4352 KB
in04.txt AC 2 ms 4352 KB
in05.txt AC 2 ms 4352 KB
in06.txt AC 2 ms 4352 KB
in07.txt WA 80 ms 8444 KB
in08.txt WA 80 ms 8444 KB
in09.txt WA 82 ms 8444 KB
in10.txt AC 80 ms 8444 KB
in11.txt WA 80 ms 8444 KB
in12.txt WA 80 ms 8444 KB
in13.txt AC 80 ms 8444 KB
in14.txt AC 80 ms 8444 KB
in15.txt AC 81 ms 8444 KB
in16.txt WA 80 ms 8444 KB
in17.txt WA 81 ms 8444 KB
in18.txt WA 2 ms 4352 KB
sample_01.txt AC 2 ms 4352 KB
sample_02.txt AC 2 ms 4352 KB