結果

問題 No.2036 Max Middle
ユーザー phspls
提出日時 2022-09-06 11:45:34
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 27,594 ms
コンパイル使用メモリ 378,800 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-11-21 13:17:56
合計ジャッジ時間 15,209 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<isize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut lsum = vec![0usize; n];
    let mut rsum = vec![0usize; n+1];
    for i in 0..n-1 {
        lsum[i+1] = lsum[i] + if a[i] < a[i+1] { 1 } else { 0 };
    }
    for i in (1..n).rev() {
        rsum[i] = rsum[i+1] + if a[i-1] > a[i] { 1 } else { 0 };
    }
    let mut result = 0usize;
    for i in 0..n {
        result += lsum[i].min(rsum[i+1]);
    }
    println!("{}", result);
}
0