結果

問題 No.616 へんなソート
コンテスト
ユーザー 👑 kakel-san
提出日時 2026-11-01 23:07:44
言語 C#
(.NET 10.0.403 + ACL)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 126 ms / 2,000 ms
+ 536µs
コード長 1,278 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,287 ms
コンパイル使用メモリ 172,968 KB
実行使用メモリ 40,576 KB
最終ジャッジ日時 2026-11-01 23:08:05
合計ジャッジ時間 12,986 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (217 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, k) = (c[0], c[1]);
        var a = NList;
        Array.Sort(a);
        var eq = 0;
        var len = n * (n - 1) / 2 + 1;
        var mod = 1_000_000_007;
        var dp = new long[len];
        dp[0] = 1;
        for (var i = 0; i < n; ++i)
        {
            var ndp = new long[len];
            if (i > 0 && a[i] == a[i - 1]) ++eq;
            else eq = 0;
            for (var j = 0; j < dp.Length; ++j)
            {
                if (dp[j] == 0) continue;
                ndp[j] = (ndp[j] + dp[j]) % mod;
                if (j + i - eq + 1 < len) ndp[j + i - eq + 1] = (ndp[j + i - eq + 1] - dp[j] + mod) % mod;
            }
            for (var j = 1; j < ndp.Length; ++j) ndp[j] = (ndp[j] + ndp[j - 1]) % mod;
            dp = ndp;
        }
        var ans = 0L;
        for (var i = 0; i <= k; ++i) ans = (ans + dp[i]) % mod;
        WriteLine(ans);
    }
}
0