結果

問題 No.528 10^9と10^9+7と回文
ユーザー RisenRisen
提出日時 2017-06-10 00:35:00
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,969 bytes
コンパイル時間 3,713 ms
コンパイル使用メモリ 110,928 KB
実行使用メモリ 25,096 KB
最終ジャッジ日時 2023-10-24 04:16:03
合計ジャッジ時間 5,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,020 KB
testcase_01 AC 28 ms
25,020 KB
testcase_02 AC 28 ms
25,020 KB
testcase_03 AC 29 ms
25,020 KB
testcase_04 AC 29 ms
25,020 KB
testcase_05 AC 29 ms
25,020 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Solution
{
    // 9で埋められる桁数
    static int GetDigits(ulong u)
    {
        int i = 0;
        while (u > 0)
        {
            i++;
            u /= 10;
        }
        return Math.Max(i - 1, 0);
    }

    // 最上位桁とそれ以外に分割
    static ulong[] Split(ulong u)
    {
        var result = new ulong[2];
        var str = u.ToString();
        result[0] = ulong.Parse(str.Substring(0, 1));
        result[1] = 0;
        if (u >= 10)
        {
            result[1] = ulong.Parse(str.Substring(1));
        }
        return result;
    }

    static void Main()
    {
        // 桁数 -> 回分数
        var palindromeA = new Dictionary<int, ulong>() { { 0, 1 }, { 1, 9 }, { 2, 9 * 2 } };
        var palindromeB = new Dictionary<int, ulong>() { { 0, 1 }, { 1, 9 }, { 2, 9 * 2 } };

        for (int i = 3; i < 18; i++)
        {
            var palA = (9 * Enumerable.Repeat(10uL, (i - 1) / 2).Aggregate((m, next) => (m * next) % 1000000000))
                + palindromeA[i - 1];
            palA %= 1000000000;
            var palB = (9 * Enumerable.Repeat(10uL, (i - 1) / 2).Aggregate((m, next) => (m * next) % 1000000007))
                + palindromeB[i - 1];
            palB %= 1000000007;

            palindromeA[i] = palA;
            palindromeB[i] = palB;
        }

        ulong resultA = 0;
        ulong resultB = 0;

        var n = ulong.Parse(Console.ReadLine());
        ulong mult = 1;
        while (mult > 0)
        {
            int digits = GetDigits(n);
            var vals = Split(n);
            mult = vals[0];
            n = vals[1];

            Console.Error.WriteLine($"{mult} {n} {digits}");
            resultA += (palindromeA[digits] * mult) % 1000000000;
            resultB += (palindromeB[digits] * mult) % 1000000007;
        }

        Console.WriteLine(resultA);
        Console.WriteLine(resultB);
    }
}
0