結果

問題 No.189 SUPER HAPPY DAY
ユーザー 紙ぺーぱー
提出日時 2015-04-18 02:54:56
言語 C#
(csc 2.8.2.62916)
結果
AC  
実行時間 308 ms
コード長 2,132 Byte
コンパイル時間 640 ms
使用メモリ 24,056 KB
最終ジャッジ日時 2019-05-12 16:21:51

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00_sample01.in AC 34 ms
13,520 KB
00_sample02.in AC 34 ms
13,364 KB
00_sample03.in AC 34 ms
15,396 KB
10_random_small01.in AC 35 ms
17,620 KB
10_random_small02.in AC 35 ms
17,616 KB
10_random_small03.in AC 34 ms
13,360 KB
10_random_small04.in AC 34 ms
15,392 KB
10_random_small05.in AC 34 ms
13,536 KB
10_random_small06.in AC 35 ms
15,580 KB
10_random_small07.in AC 34 ms
15,580 KB
10_random_small08.in AC 35 ms
13,364 KB
10_random_small09.in AC 36 ms
17,620 KB
10_random_small10.in AC 35 ms
17,612 KB
20_random_large01.in AC 128 ms
15,636 KB
20_random_large02.in AC 175 ms
19,088 KB
20_random_large03.in AC 183 ms
19,384 KB
20_random_large04.in AC 218 ms
20,168 KB
20_random_large05.in AC 221 ms
20,284 KB
20_random_large06.in AC 174 ms
17,100 KB
20_random_large07.in AC 264 ms
22,888 KB
20_random_large08.in AC 90 ms
17,452 KB
20_random_large09.in AC 84 ms
18,236 KB
20_random_large10.in AC 38 ms
15,580 KB
30_corner01.in AC 174 ms
22,384 KB
30_corner02.in AC 174 ms
20,344 KB
30_corner03.in AC 308 ms
24,056 KB
テストケース一括ダウンロード
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 2.8.2.62916 (2ad4aabc)
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