結果

問題 No.162 8020運動
ユーザー eitahoeitaho
提出日時 2015-03-06 21:20:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 3,254 bytes
コンパイル時間 3,062 ms
コンパイル使用メモリ 113,428 KB
実行使用メモリ 25,792 KB
最終ジャッジ日時 2023-09-06 15:31:01
合計ジャッジ時間 9,854 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
23,808 KB
testcase_01 AC 134 ms
23,592 KB
testcase_02 AC 189 ms
21,720 KB
testcase_03 AC 254 ms
23,824 KB
testcase_04 AC 255 ms
23,708 KB
testcase_05 AC 256 ms
25,756 KB
testcase_06 AC 248 ms
21,696 KB
testcase_07 AC 255 ms
23,696 KB
testcase_08 AC 250 ms
25,792 KB
testcase_09 AC 71 ms
25,776 KB
testcase_10 AC 185 ms
23,760 KB
testcase_11 AC 134 ms
21,836 KB
testcase_12 AC 93 ms
21,816 KB
testcase_13 AC 249 ms
21,888 KB
testcase_14 AC 74 ms
19,700 KB
testcase_15 AC 77 ms
23,652 KB
testcase_16 AC 104 ms
25,636 KB
testcase_17 AC 84 ms
23,860 KB
testcase_18 AC 234 ms
23,724 KB
testcase_19 AC 183 ms
23,724 KB
testcase_20 AC 199 ms
21,700 KB
testcase_21 AC 202 ms
23,792 KB
testcase_22 AC 182 ms
21,880 KB
testcase_23 AC 203 ms
23,800 KB
testcase_24 AC 194 ms
25,680 KB
testcase_25 AC 215 ms
23,800 KB
testcase_26 AC 71 ms
23,556 KB
testcase_27 AC 144 ms
23,636 KB
testcase_28 AC 235 ms
23,752 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Enu = System.Linq.Enumerable;

class Program
{
    static readonly int NumTeeth = 14;
    static readonly int Target = 80;
    double[] Prob;
    double?[,] memo;

    void Solve()
    {
        int Age = reader.Int();
        Prob = Enu.Range(0, 3).Select(i => 1 - reader.Double() / 100).ToArray();
        int rem = Target - Age;
        memo = new double?[rem + 1, NumTeeth + 1];
        double ans = Rec(rem, NumTeeth) * 2;
        Console.WriteLine(ans);
    }

    private double Rec(int rem, int len)
    {
        if (rem == 0 || len == 0) return len;
        if (memo[rem, len].HasValue) return memo[rem, len].Value;
        if (len == 1) return Prob[0] * Rec(rem - 1, 1);
        double res = 0;

        for (int next = 0; next < (1 << len); next++)
        {
            int count = 0;
            double p = 1, sum = 0;
            for (int i = 0; i <= len; i++)
            {
                if ((next >> i & 1) == 1)
                {
                    count++;
                    p *= (i == 0 || i == len - 1) ? Prob[1] : Prob[2];
                }
                else
                {
                    sum += Rec(rem - 1, count);
                    count = 0;
                    if (i < len) p *= (i == 0 || i == len - 1) ? 1 - Prob[1] : 1 - Prob[2];
                }
            }
            res += p * sum;
        }

        memo[rem, len] = res;
        return res;
    }

    int BitCount(int x) { return x == 0 ? 0 : 1 + BitCount(x & x - 1); }




    Reader reader = new Reader(Console.In);
    static void Main() { new Program().Solve(); }
}

class Reader
{
    private readonly TextReader reader;
    private readonly char[] separator = { ' ' };
    private readonly StringSplitOptions removeOp = StringSplitOptions.RemoveEmptyEntries;
    private string[] A = new string[0];
    private int i;

    public Reader(TextReader r) { reader = r; }
    public Reader(string file) { reader = new StreamReader(file); }
    public bool HasNext() { return Enqueue(); }
    public string String() { return Dequeue(); }
    public int Int() { return int.Parse(Dequeue()); }
    public long Long() { return long.Parse(Dequeue()); }
    public double Double() { return double.Parse(Dequeue()); }
    public int[] IntLine() { var s = Line(); return s == "" ? new int[0] : Array.ConvertAll(Split(s), int.Parse); }
    public int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public int[][] IntGrid(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public string Line() { return reader.ReadLine().Trim(); }
    private string[] Split(string s) { return s.Split(separator, removeOp); }
    private bool Enqueue()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return Enqueue();
        A = Split(line);
        i = 0;
        return true;
    }
    private string Dequeue() { Enqueue(); return A[i++]; }
}
0