結果

問題 No.2036 Max Middle
ユーザー phspls
提出日時 2022-09-13 11:11:51
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 11,776 ms
コンパイル使用メモリ 377,892 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-11-30 14:25:40
合計ジャッジ時間 14,051 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 lefts = vec![0usize; n];
    let mut rights = vec![0usize; n];
    for i in 0..n-1 {
        lefts[i+1] = lefts[i];
        if a[i] < a[i+1] {
            lefts[i+1] += 1;
        }
    }
    for i in (1..n).rev() {
        rights[i-1] = rights[i];
        if a[i-1] > a[i] {
            rights[i-1] += 1;
        }
    }
    let result = (0..n).map(|i| lefts[i].min(rights[i])).sum::<usize>();
    println!("{}", result);
}
0