結果

問題 No.1953 8
ユーザー 👑 kakel-sankakel-san
提出日時 2024-02-08 23:00:37
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,814 bytes
コンパイル時間 8,542 ms
コンパイル使用メモリ 158,376 KB
実行使用メモリ 179,784 KB
最終ジャッジ日時 2024-02-08 23:00:59
合計ジャッジ時間 15,144 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
32,548 KB
testcase_01 AC 75 ms
32,548 KB
testcase_02 AC 75 ms
32,676 KB
testcase_03 AC 75 ms
32,548 KB
testcase_04 AC 75 ms
32,676 KB
testcase_05 AC 75 ms
32,676 KB
testcase_06 AC 74 ms
32,676 KB
testcase_07 AC 76 ms
32,676 KB
testcase_08 AC 75 ms
32,676 KB
testcase_09 AC 76 ms
32,676 KB
testcase_10 AC 79 ms
32,676 KB
testcase_11 AC 75 ms
32,676 KB
testcase_12 AC 76 ms
32,676 KB
testcase_13 AC 77 ms
32,676 KB
testcase_14 AC 76 ms
32,676 KB
testcase_15 AC 76 ms
32,676 KB
testcase_16 AC 75 ms
32,676 KB
testcase_17 AC 75 ms
32,676 KB
testcase_18 AC 101 ms
32,676 KB
testcase_19 AC 78 ms
32,676 KB
testcase_20 AC 75 ms
32,676 KB
testcase_21 AC 75 ms
32,676 KB
testcase_22 AC 75 ms
32,676 KB
testcase_23 AC 75 ms
32,676 KB
testcase_24 AC 77 ms
32,804 KB
testcase_25 AC 76 ms
32,804 KB
testcase_26 AC 75 ms
32,804 KB
testcase_27 AC 75 ms
32,804 KB
testcase_28 AC 75 ms
32,676 KB
testcase_29 AC 75 ms
179,784 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (121 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

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 int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var k = long.Parse(ReadLine());
        var ok = 99_193_752_409_910_741;
        var ng = 0L;
        while (ok - ng > 1)
        {
            var mid = (ok + ng) / 2;
            var sum = Calc(mid);
            if (sum == k)
            {
                WriteLine(mid);
                return;
            }
            if (sum > k) ok = mid;
            else ng = mid;
        }
        WriteLine(-1);
    }
    static long Calc(long n)
    {
        var s = n.ToString().Select(c => c - '0').ToArray();
        var count = 0L;
        var dp = new long[20];
        for (var j = 1; j < s[0]; ++j)
        {
            ++dp[j];
            ++count;
        }
        ++dp[s[0] + 10];
        for (var i = 1; i < s.Length; ++i)
        {
            var ndp = new long[20];
            for (var j = 0; j < 10; ++j) ndp[j] = dp[j] * 10 + count + (j > 0 ? 1 : 0);
            count = count * 10 + 9;
            for (var p = 0; p < 10; ++p) ndp[p] += dp[p + 10] * s[i];
            for (var j = 0; j < s[i]; ++j)
            {
                ++ndp[j];
                ++count;
            }
            for (var p = 10; p < 20; ++p) ndp[p] = dp[p];
            ++ndp[s[i] + 10];
            dp = ndp;
        }
        return dp[0] + dp[4] + dp[6] + dp[8] * 2 + dp[9] + dp[10] + dp[14] + dp[16] + dp[18] * 2 + dp[19];
    }
}
0