結果

問題 No.528 10^9と10^9+7と回文
ユーザー RisenRisen
提出日時 2017-06-10 12:07:17
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,619 bytes
コンパイル時間 1,340 ms
コンパイル使用メモリ 111,468 KB
実行使用メモリ 25,388 KB
最終ジャッジ日時 2023-10-24 20:24:55
合計ジャッジ時間 2,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,212 KB
testcase_01 AC 28 ms
25,212 KB
testcase_02 WA -
testcase_03 AC 29 ms
25,232 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 WA -
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
{
    // nについて,すべての桁が1以上である場合の回文のバリエーションを得る
    static ulong GetPalindromeCount1(ulong n, int mod)
    {
        var list = n.ToString().Select(c => int.Parse(c.ToString())).ToList();
        var reverse = ((IEnumerable<int>)list).Reverse();

        // 最上位は0を取れないのでバリエーションを1減らす
        if (n > 0)
        {
            list[0]--;
        }

        // 半分で折り返して重ねて,各桁の最小値+1の積を取る
        // +1は0がバリエーションにあるため
        var count = list.Take((list.Count + 1) / 2).Zip(reverse, (i, j) => Math.Min(i, j) + 1).Aggregate(1UL, (prod, next) => (prod * (ulong)next) % (ulong)mod);
        return count;
    }

    // nについて,最上位桁が0である場合の回文のバリエーションを得る
    static ulong GetPalindromeCount0(ulong n, int mod)
    {
        // 桁数
        var digits = n.ToString().Length - 1;
        if (digits <= 0)
        {
            return 0;
        }
        var nines = ulong.Parse(new string(Enumerable.Repeat('9', digits).ToArray()));
        return GetPalindromeCount1(nines, mod);
    }


    static void Main()
    {
        var dividers = new int[] { 1000000000, 1000000007 };
        var n = ulong.Parse(Console.ReadLine());

        foreach (var div in dividers)
        {
            var pal = GetPalindromeCount0(n, div) + GetPalindromeCount1(n, div);
            Console.WriteLine(pal);
        }

    }
}
0