結果

問題 No.189 SUPER HAPPY DAY
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2015-04-18 02:54:56
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 351 ms / 5,000 ms
コード長 2,132 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 107,900 KB
実行使用メモリ 31,768 KB
最終ジャッジ日時 2023-09-17 22:31:07
合計ジャッジ時間 7,863 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
20,864 KB
testcase_01 AC 66 ms
22,860 KB
testcase_02 AC 65 ms
20,856 KB
testcase_03 AC 65 ms
20,824 KB
testcase_04 AC 65 ms
20,836 KB
testcase_05 AC 65 ms
18,872 KB
testcase_06 AC 66 ms
18,828 KB
testcase_07 AC 65 ms
20,864 KB
testcase_08 AC 67 ms
20,880 KB
testcase_09 AC 66 ms
22,924 KB
testcase_10 AC 66 ms
22,896 KB
testcase_11 AC 65 ms
22,916 KB
testcase_12 AC 66 ms
20,776 KB
testcase_13 AC 158 ms
23,208 KB
testcase_14 AC 202 ms
22,332 KB
testcase_15 AC 213 ms
26,880 KB
testcase_16 AC 254 ms
25,780 KB
testcase_17 AC 245 ms
25,932 KB
testcase_18 AC 204 ms
24,672 KB
testcase_19 AC 275 ms
24,312 KB
testcase_20 AC 123 ms
23,920 KB
testcase_21 AC 115 ms
21,760 KB
testcase_22 AC 68 ms
20,896 KB
testcase_23 AC 210 ms
26,020 KB
testcase_24 AC 210 ms
27,956 KB
testcase_25 AC 351 ms
31,768 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
static public class Program
{
    static public void Main()
    {
        var max = BigInteger.Pow(10, 200);
        const long mod = (long)1e9 + 9;
        var S = readString(2).ValidateArray(x =>
        {
            var v = BigInteger.Parse(x);
            return 1 <= v && v <= max;
        });
        readEOF();
        var a = func(S[0]);
        var b = func(S[1]);
        long ans = 0;
        for (int i = 1; i < Math.Min(a.Length, b.Length); i++)
            ans = (ans + a[i] * b[i]) % mod;
        Console.WriteLine(ans);
    }
    static long[] func(string str)
    {
        const long mod = (long)1e9 + 9;
        var len = str.Length;
        var max = len * 9;
        var dp = new long[2, len + 1, max + 10];
        dp[1, 0, 0] = 1;
        for (int i = 0; i < len; i++)
            for (int j = 0; j <= max; j++)
                for (int k = 0; k < 10; k++)
                {
                    if (k == str[i] - '0')
                        dp[1, i + 1, j + k] = (dp[1, i + 1, j + k] + dp[1, i, j]) % mod;
                    else if (k < str[i] - '0') dp[0, i + 1, j + k] = (dp[0, i + 1, j + k] + dp[1, i, j]) % mod;
                    dp[0, i + 1, j + k] = (dp[0, i + 1, j + k] + dp[0, i, j]) % mod;
                }
        var ret = new long[max + 10];
        for (int i = 0; i <= max; i++)
            ret[i] = (dp[0, len, i] + dp[1, len, i]) % mod;
        return ret;
    }
    static string[] readString(int n)
    {
        var s = Console.ReadLine().Split(' ');
        if (s.Length != n)
            throw new Exception(string.Format("invalid input, expected{0} actual{1}", n, s.Length));
        return s;
    }
    static void readEOF()
    {
        if (Console.In.Peek() >= 0)
            throw new Exception("invalid input too long input file");
    }

}
static public class Ex
{
    static public T[] ValidateArray<T>(this T[] input, Func<T, bool> f)
    {
        foreach (var x in input)
            if (!f(x))
                throw new Exception("invalid input");
        return input;
    }
}
0