結果

問題 No.2036 Max Middle
ユーザー phsplsphspls
提出日時 2022-09-13 11:11:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 7,115 ms
コンパイル使用メモリ 143,344 KB
実行使用メモリ 8,796 KB
最終ジャッジ日時 2023-08-20 12:38:53
合計ジャッジ時間 9,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 11 ms
5,572 KB
testcase_09 AC 18 ms
8,180 KB
testcase_10 AC 18 ms
8,500 KB
testcase_11 AC 13 ms
8,124 KB
testcase_12 AC 11 ms
7,808 KB
testcase_13 AC 18 ms
8,596 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 16 ms
8,796 KB
testcase_17 AC 10 ms
6,992 KB
testcase_18 AC 12 ms
7,732 KB
testcase_19 AC 13 ms
7,912 KB
testcase_20 AC 16 ms
8,068 KB
権限があれば一括ダウンロードができます

ソースコード

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