Submission #1371405


Source Code Expand

use std::io;
use std::collections::VecDeque;

fn main() {
    let mut input = Input::new();
    let n: usize = input.next();
    let x: i64 = input.next();
    let mut a: Vec<i64> = vec![0;n];
    for i in 0..n {
        a[i] = input.next();
    }
    let mut t: Vec<i64> = vec![i64::max_value();n];
    let mut v = i64::max_value();
    for i in 0..n {
        let mut s: i64 = 0;
        for j in 0..n {
            let k = if j < i { a[n + j - i] } else { a[j - i] };
            if t[j] > k {
                t[j] = k;
            }
            s += t[j];
        }
        if v > s + i as i64 * x {
            v = s + i as i64 * x;
        }
    }
    println!("{}", v);
}

struct Input {
    queue: VecDeque<String>,
}

impl Input {
    fn new() -> Input {
        Input { queue: VecDeque::new() }
    }

    fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        if self.queue.is_empty() {
            let mut line = String::new();
            let _ = io::stdin().read_line(&mut line);
            for x in line.split_whitespace() {
                self.queue.push_back(String::from(x));
            }
        }
        return self.queue.pop_front().unwrap().parse::<T>().unwrap();
    }
}

Submission Info

Submission Time
Task B - Colorful Slimes
User hoshi524
Language Rust (1.15.1)
Score 400
Code Size 1312 Byte
Status AC
Exec Time 11 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 21
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 4352 KB
0_01.txt AC 2 ms 4352 KB
0_02.txt AC 2 ms 4352 KB
1_00.txt AC 9 ms 4352 KB
1_01.txt AC 9 ms 4352 KB
1_02.txt AC 10 ms 4352 KB
1_03.txt AC 10 ms 4352 KB
1_04.txt AC 11 ms 4352 KB
1_05.txt AC 11 ms 4352 KB
1_06.txt AC 10 ms 4352 KB
1_07.txt AC 10 ms 4352 KB
1_08.txt AC 10 ms 4352 KB
1_09.txt AC 10 ms 4352 KB
1_10.txt AC 8 ms 4352 KB
1_11.txt AC 10 ms 4352 KB
1_12.txt AC 9 ms 4352 KB
1_13.txt AC 7 ms 4352 KB
1_14.txt AC 10 ms 4352 KB
1_15.txt AC 8 ms 4352 KB
1_16.txt AC 9 ms 4352 KB
1_17.txt AC 10 ms 4352 KB