結果

問題 No.1687 What the Heck?
ユーザー bluemegane
提出日時 2021-09-25 07:15:10
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 107,568 KB
実行使用メモリ 44,264 KB
最終ジャッジ日時 2024-07-05 11:58:47
合計ジャッジ時間 4,307 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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