結果

問題 No.2036 Max Middle
ユーザー phsplsphspls
提出日時 2022-09-13 11:11:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 11,441 ms
コンパイル使用メモリ 378,568 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-05-07 19:16:24
合計ジャッジ時間 13,714 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,248 KB
testcase_02 AC 0 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 10 ms
5,632 KB
testcase_09 AC 16 ms
8,320 KB
testcase_10 AC 16 ms
8,448 KB
testcase_11 AC 11 ms
8,320 KB
testcase_12 AC 11 ms
7,936 KB
testcase_13 AC 18 ms
8,704 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 15 ms
8,832 KB
testcase_17 AC 9 ms
6,912 KB
testcase_18 AC 10 ms
7,808 KB
testcase_19 AC 11 ms
7,936 KB
testcase_20 AC 14 ms
8,192 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