結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー bluemeganebluemegane
提出日時 2020-06-27 18:55:22
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,488 bytes
コンパイル時間 1,022 ms
コンパイル使用メモリ 63,804 KB
実行使用メモリ 47,376 KB
最終ジャッジ日時 2023-09-19 07:13:56
合計ジャッジ時間 7,626 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,548 KB
testcase_01 AC 59 ms
20,724 KB
testcase_02 AC 59 ms
20,700 KB
testcase_03 AC 58 ms
20,756 KB
testcase_04 WA -
testcase_05 AC 59 ms
20,672 KB
testcase_06 AC 58 ms
22,652 KB
testcase_07 AC 58 ms
20,572 KB
testcase_08 WA -
testcase_09 AC 58 ms
22,536 KB
testcase_10 WA -
testcase_11 AC 58 ms
20,596 KB
testcase_12 WA -
testcase_13 AC 71 ms
21,452 KB
testcase_14 AC 70 ms
21,476 KB
testcase_15 WA -
testcase_16 AC 70 ms
19,228 KB
testcase_17 WA -
testcase_18 AC 70 ms
21,592 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 70 ms
19,424 KB
testcase_23 AC 183 ms
45,204 KB
testcase_24 AC 181 ms
45,192 KB
testcase_25 AC 181 ms
47,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 181 ms
47,224 KB
testcase_29 AC 179 ms
47,212 KB
testcase_30 AC 179 ms
47,156 KB
testcase_31 AC 179 ms
47,324 KB
testcase_32 AC 178 ms
47,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var b = Array.ConvertAll(line, x => -int.Parse(x));
        var ans1 = getAns(n, a);
        var ans2 = getAns(n, b);
        int ans;
        if (ans1 == -1 && ans2 == -1) ans = -1;
        else if (ans1 == -1) ans = ans2;
        else if (ans2 == -1) ans = ans1;
        else ans = Min(ans1, -ans2);
        Console.WriteLine(ans);
    }
    static int getAns(int n, int[] a)
    {
        var bL = new int[n];
        var br = new int[n];
        bL[0] = a[0];
        br[n - 1] = a[n - 1];
        for (int i = 1; i < n; i++)
        {
            if (a[i] < bL[i - 1]) bL[i] = a[i];
            else bL[i] = bL[i - 1];
            if (a[n - 1 - i] < br[n - i]) br[n - 1 - i] = a[n - 1 - i];
            else br[n - 1 - i] = br[n - i];
        }
        var res = getAns1(n, a, bL, br);
        return res;
    }
    static int getAns1(int n, int[] a, int[] bL, int[] br)
    {
        var res = int.MaxValue;
        for (int i = 1; i < n - 1; i++)
        {
            if (a[i] > bL[i - 1] && a[i] > br[i + 1])
            {
                var t = a[i] + bL[i - 1] + br[i + 1];
                res = Min(res, t);
            }
        }
        if (res == int.MaxValue) return -1;
        else return res;
    }
}
0