結果

問題 No.1687 What the Heck?
ユーザー bluemegane
提出日時 2021-09-24 22:26:28
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 619 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 113,408 KB
実行使用メモリ 45,548 KB
最終ジャッジ日時 2024-07-05 10:54:55
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 ans = n * (n + 1) / 2L;
        var pp = 0;
        for (int i = 0; i < n; i++)
        {
            if (p[i] == n) { pp = i + 1; break; }
        }
        ans -= 2L * pp;
        Console.WriteLine(Max(0, ans));
    }
}
0