結果

問題 No.2055 12x34...
ユーザー kakel-san
提出日時 2022-08-28 21:21:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 4,561 ms
コンパイル使用メモリ 105,984 KB
実行使用メモリ 46,180 KB
最終ジャッジ日時 2024-10-15 18:16:25
合計ジャッジ時間 12,757 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var n = NN;
        var a = NList;
        var mod = 998_244_353;
        var ncnt = new Dictionary<int, long>();
        var ecnt = new Dictionary<int, long>();
        for (var i = 0; i < n; ++i)
        {
            var add = 0L;
            if (ncnt.ContainsKey(a[i] - 1))
            {
                add = (ncnt[a[i] - 1] + ecnt[a[i] - 1]) % mod;
            }
            if (ncnt.ContainsKey(a[i]))
            {
                ncnt[a[i]] += 1;
                ecnt[a[i]] = (ecnt[a[i]] + add) % mod;
            }
            else
            {
                ncnt[a[i]] = 1;
                ecnt[a[i]] = add;
            }
        }
        var res = 0L;
        foreach (var kv in ecnt) res = (res + kv.Value) % mod;
        WriteLine(res);
    }
}
0