結果

問題 No.41 貯金箱の溜息(EASY)
ユーザー syoken_desukasyoken_desuka
提出日時 2015-03-01 15:58:44
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 5,450 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 113,128 KB
実行使用メモリ 28,696 KB
最終ジャッジ日時 2024-06-24 00:32:12
合計ジャッジ時間 1,652 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
28,696 KB
testcase_01 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.Collections;
using System.Linq;
using System.Text;
using System.Numerics;
using sc = Scanner;

class Program
{
    static void Main(string[] args)
    {
        Solver solver = new Solver();
        solver.Solve();
#if DEBUG
        System.Console.WriteLine("続行するには何かキーを押してください...");
        System.Console.ReadKey();
#endif

    }
}

public class Solver
{
#region IGNORE_ME
    public Solver()
    {
        //こんすとらくたん きにしなくてよろしい
    }
#endregion IGNORE_ME


#region FIELD
    static long[,] memo;
    static bool[,] alreadyReached;
#endregion FIELD

    int[] devider = { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

    public void Solve()
    {
        int t = sc.NextInt();
        int[] quary = new int[t];
        memo = new long[10000000000 / 111111 + 10,devider.Length];
        alreadyReached = new bool[10000000000 / 111111 + 10, devider.Length];
        for (int i = 0; i < t; i++)
        {
            quary[i] = sc.NextInt();
        }

        for (int i = 0; i < t; i++)
        {
            int elem = quary[i] / 111111;
#if DEBUG
            Console.WriteLine("{0} {1}",elem,Math.Min(9,elem));
#endif 
            Console.WriteLine(memoDFS(elem,Math.Min(9,elem)));//start 999999 or below 999999(ex 111111 migi 1, 333333 migi 3)

        }

#if DEBUG
        Console.WriteLine("local check"); // Visual Studioのローカル変数チェック用 MainにいくとSolve内のローカル変数消えちゃう
#endif 
    }

    long memoDFS(int remain, int usedMoney)
    {

        long answer = 0;
        if (remain == 0)
        {
            return 1;
        }
        if (alreadyReached[remain, usedMoney])
        {
#if DEBUG
            Console.WriteLine("alCalc {0} {1} =:: {2}",remain, usedMoney,memo[remain,usedMoney]);
#endif 
            return memo[remain, usedMoney];
        }
        for (int i = 0; i < usedMoney+1; i++)
        {
            if (devider[i] <= remain)
            {
#if DEBUG
        Console.WriteLine("{0} - {1}",remain , devider[i]);
#endif 
                answer = (answer + memoDFS(remain - devider[i], i)) % 1000000009;
            }
            else break;
        }
        alreadyReached[remain, usedMoney] = true;
        memo[remain, usedMoney] = answer;
        return answer;
    }
}

/// <summary>
/// Java風のスキャナー,自作(某最速の人を参考) 自分の実装のせいか,バグってるっぽい バグが出たらO(n^3) n=100000 でTLE
/// </summary>
public static class Scanner
{
    public static string NextString()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
                tmp += data;
        }
        return tmp;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
                tmp += data;
        }
        return int.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
                tmp += data;
        }
        return long.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
                tmp += data;
        }
        return double.Parse(tmp);
    }

    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static double[] NextDoubleArray()
    {
        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}

0