結果

問題 No.528 10^9と10^9+7と回文
ユーザー 14番14番
提出日時 2017-06-10 00:16:09
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,847 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 111,648 KB
実行使用メモリ 208,416 KB
最終ジャッジ日時 2023-10-24 03:53:54
合計ジャッジ時間 3,873 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

public class Program
{

    public void Proc()
    {
        this.Target = Reader.ReadLine();
        long[] ans = new long[2];
        for (int i = 1; i <= this.Target.Length; i++) {
            long[] tmp = GetAns(i, true);
            ans[0] += tmp[0];
            ans[1] += tmp[1];
            ans[0] = ans[0] % ModZero;
            ans[1] = ans[1] % Mod;
        }
        Console.WriteLine(ans[0]);
		Console.WriteLine(ans[1]);

	}

    private Dictionary<int, Dictionary<bool, long[]>> dic = new Dictionary<int, Dictionary<bool, long[]>>();


    private string Target;

    private bool IsBigger(string num) {
        if(num.Length > Target.Length) {
            return true;
        }
        if(num.Length < Target.Length) {
            return false;
        }
        for (int i = 0; i < num.Length; i++) {
            if(num[0]>Target[0]) {
                return true;
            }
            if(num[0]<Target[0]) {
                return false;
            }
        }
        return false;
    }

    private long[] GetAns(int keta, bool rmZero) {
        if(!dic.ContainsKey(keta)) {
            dic.Add(keta, new Dictionary<bool, long[]>());
        }
        if(dic[keta].ContainsKey(rmZero)) {
            return dic[keta][rmZero];
        }

        if(keta == 1) {
            if(Target.Length == 1) {
                int tmp = int.Parse(Target);
                return new long[] { tmp, tmp };
            }
            if(rmZero) {
                return new long[] { 9, 9 };
            }
            return new long[] { 10, 10 };
        }
        if(keta == 2) {
            if(Target.Length == 2) {
                int tmp = int.Parse(Target);
                int cnt = 0;
                for (int i = 1; i * 11 <= tmp; i++) {
                    cnt++;
                }
                return new long[] { cnt, cnt };
            }
            if(rmZero) {
                return new long[] { 9, 9 };
            }
            return new long[] { 10, 10 };
        }
        long[] baseNum = GetAns(keta - 2, false).ToArray();
        long[] ans = new long[2];
        if(keta < this.Target.Length) {
            if(rmZero) {
                ans[0] = baseNum[0] * 9;
                ans[1] = baseNum[1] * 9;
            } else {
				ans[0] = baseNum[0] * 10;
				ans[1] = baseNum[1] * 10;
			}
        } else {
            ans = GetTargetSmallerNum(0);
        }
        ans[0] = ans[0] % ModZero;
        ans[1] = ans[1] % Mod;
        dic[keta][rmZero] = ans;
        return ans;
    }

    private long[] GetTargetSmallerNum(int idx) {
        if (idx >= Target.Length) {
            return new long[] { 0, 0 };
        }
        int num = int.Parse(Target[idx].ToString());

        int keta = Target.Length - idx - 1;

        long[] tmp = new long[2];
        if(num>=1) {
            tmp = GetAns(keta, false).ToArray();
			tmp[0] *= (num - 1);
			tmp[1] *= (num - 1);
		}
        long[] tmp2 = GetTargetSmallerNum(idx + 1).ToArray();
        long[] ans = new long[] { tmp[0] + tmp2[0], tmp[1] + tmp2[1] };
        ans[0] = ans[0] % ModZero;
        ans[1] = ans[1] % Mod;
        return ans;
    }

    private long ModZero = 1000000000;
    private long Mod = 1000000000 + 7;

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"




1000000000000000000000000000000








";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
0