結果

問題 No.1687 What the Heck?
ユーザー bluemeganebluemegane
提出日時 2021-09-25 07:15:10
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 63,468 KB
実行使用メモリ 40,812 KB
最終ジャッジ日時 2023-09-18 22:49:04
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,612 KB
testcase_01 AC 56 ms
18,552 KB
testcase_02 AC 57 ms
18,712 KB
testcase_03 AC 57 ms
20,708 KB
testcase_04 AC 57 ms
18,692 KB
testcase_05 AC 57 ms
20,776 KB
testcase_06 AC 58 ms
20,680 KB
testcase_07 AC 88 ms
28,204 KB
testcase_08 AC 95 ms
27,344 KB
testcase_09 AC 86 ms
26,088 KB
testcase_10 AC 78 ms
24,620 KB
testcase_11 AC 80 ms
22,920 KB
testcase_12 AC 133 ms
40,812 KB
testcase_13 AC 132 ms
38,668 KB
testcase_14 AC 134 ms
38,764 KB
testcase_15 AC 132 ms
38,740 KB
testcase_16 AC 132 ms
38,528 KB
testcase_17 AC 70 ms
21,656 KB
testcase_18 AC 134 ms
38,604 KB
testcase_19 AC 65 ms
20,816 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 p = Array.ConvertAll(line, int.Parse);
        getAns(n, p);
    }
    static void getAns(int n, int[] p)
    {
        if (n == 1) { Console.WriteLine(0); return; }
        var a = new int[n + 1];
        for (int i = 0; i < n; i++) a[p[i]] = i + 1;
        long t = a[1] - a[2];
        var ans = t;
        for (int i = 3; i <= n; i++)
        {
            t += 2L * a[i - 1] - a[i];
            ans = Max(ans, t);
        }
        Console.WriteLine(Max(0, ans));
    }
}
0