結果

問題 No.372 It's automatic
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2016-05-14 02:39:42
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,216 ms / 6,000 ms
コード長 2,129 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 112,924 KB
実行使用メモリ 17,900 KB
最終ジャッジ日時 2024-04-15 19:22:41
合計ジャッジ時間 32,947 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
17,396 KB
testcase_01 AC 23 ms
17,644 KB
testcase_02 AC 22 ms
17,640 KB
testcase_03 AC 22 ms
17,648 KB
testcase_04 AC 2,199 ms
17,900 KB
testcase_05 AC 2,204 ms
17,764 KB
testcase_06 AC 2,165 ms
17,784 KB
testcase_07 AC 2,211 ms
17,532 KB
testcase_08 AC 2,205 ms
17,784 KB
testcase_09 AC 2,215 ms
17,520 KB
testcase_10 AC 2,213 ms
17,648 KB
testcase_11 AC 2,204 ms
17,656 KB
testcase_12 AC 2,216 ms
17,788 KB
testcase_13 AC 2,191 ms
17,524 KB
testcase_14 AC 2,181 ms
17,520 KB
testcase_15 AC 2,208 ms
17,648 KB
testcase_16 AC 25 ms
17,524 KB
testcase_17 AC 25 ms
17,776 KB
testcase_18 AC 24 ms
17,764 KB
testcase_19 AC 25 ms
17,784 KB
testcase_20 AC 24 ms
17,640 KB
testcase_21 AC 921 ms
17,524 KB
testcase_22 AC 920 ms
17,644 KB
testcase_23 AC 916 ms
17,524 KB
testcase_24 AC 912 ms
17,648 KB
testcase_25 AC 894 ms
17,528 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.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Number = System.Int64;
using Point = System.Numerics.Complex;
namespace Program
{
    public class Solver
    {
        static void Main()
        {
            var s = Console.ReadLine();
            var m = int.Parse(Console.ReadLine());
            var n = s.Length;
            var dp = new uint[20050];
            var next = new uint[20050];
            var ans = 0u;
            var ten = new int[20050];
            for (int i = 0; i < m; i++)
                ten[i] = (i * 10) % m;
            const int MOD = 1000000007;
            if (m < 20)
            {
                foreach (var x in s)
                {
                    var v = x - '0';
                    Buffer.BlockCopy(dp, 0, next, 0, sizeof(uint) * 20050);
                    if (v > 0) next[v % m]++;
                    else ans++;
                    for (int j = 0; j < m; j++)
                    {
                        var to = ten[j] + v;
                        if (to >= m) to %= m;
                        if ((next[to] += dp[j]) >= MOD) next[to] -= MOD;
                    }
                    Swap(ref dp, ref next);
                }
            }
            else
            {
                foreach (var x in s)
                {
                    var v = x - '0';
                    Buffer.BlockCopy(dp, 0, next, 0, sizeof(uint) * 20050);
                    if (v > 0) next[v % m]++;
                    else ans++;
                    for (int j = 0; j < 20050; j++)
                    {
                        var to = ten[j] + v;
                        if (to >= m) to -= m;
                        if ((next[to] += dp[j]) >= MOD) next[to] -= MOD;
                    }
                    Swap(ref dp, ref next);
                }
            }
            Console.WriteLine((dp[0] + ans) % MOD);


        }

        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}
0