結果

問題 No.2036 Max Middle
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-10 22:29:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 68,112 KB
実行使用メモリ 49,044 KB
最終ジャッジ日時 2023-10-10 22:29:41
合計ジャッジ時間 6,548 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,640 KB
testcase_01 AC 60 ms
21,504 KB
testcase_02 AC 59 ms
23,728 KB
testcase_03 AC 65 ms
21,584 KB
testcase_04 AC 59 ms
23,620 KB
testcase_05 AC 59 ms
21,712 KB
testcase_06 AC 59 ms
21,612 KB
testcase_07 AC 60 ms
23,668 KB
testcase_08 AC 118 ms
39,024 KB
testcase_09 AC 157 ms
45,588 KB
testcase_10 AC 162 ms
45,692 KB
testcase_11 AC 144 ms
41,516 KB
testcase_12 AC 149 ms
42,212 KB
testcase_13 AC 165 ms
45,676 KB
testcase_14 AC 68 ms
23,920 KB
testcase_15 AC 68 ms
21,900 KB
testcase_16 AC 171 ms
49,044 KB
testcase_17 AC 121 ms
38,804 KB
testcase_18 AC 136 ms
40,112 KB
testcase_19 AC 138 ms
42,416 KB
testcase_20 AC 150 ms
45,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        var left = new int[n];
        var right = new int[n];
        for (var i = 1; i < n; ++i)
        {
            left[i] = left[i - 1] + (a[i - 1] < a[i] ? 1 : 0);
        }
        for (var i = n - 2; i >= 0; --i)
        {
            right[i] = right[i + 1] + (a[i] > a[i + 1] ? 1 : 0);
        }
        var ans = 0L;
        for (var i = 0; i < n; ++i) ans += Math.Min(left[i], right[i]);
        WriteLine(ans);
    }
}
0