結果
| 問題 |
No.528 10^9と10^9+7と回文
|
| ユーザー |
Risen
|
| 提出日時 | 2017-06-10 00:35:00 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,969 bytes |
| コンパイル時間 | 3,022 ms |
| コンパイル使用メモリ | 112,252 KB |
| 実行使用メモリ | 27,136 KB |
| 最終ジャッジ日時 | 2024-09-22 21:14:25 |
| 合計ジャッジ時間 | 3,384 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 3 RE * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}
Risen