結果

問題 No.2053 12345...
ユーザー bluemegane
提出日時 2022-08-27 10:11:45
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 111,416 KB
実行使用メモリ 41,472 KB
最終ジャッジ日時 2024-10-14 08:50:35
合計ジャッジ時間 5,535 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Linq;
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);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var b = new List<int>();
        var tc = 0;
        for (int i = 1; i < n; i++)
        {
            if (a[i] - a[i - 1] == 1) tc++;
            else
            {
                if (tc > 0) b.Add(tc);
                tc = 0;
            }
        }
        if (tc > 0) b.Add(tc);
        var ans = 0L;
        foreach (var x in b)
            ans += (long)x * (x + 1) / 2L;
        Console.WriteLine(ans);
    }
}
0