結果

問題 No.309 シャイな人たち (1)
ユーザー eitahoeitaho
提出日時 2015-12-02 15:38:02
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 4,207 bytes
コンパイル時間 2,781 ms
コンパイル使用メモリ 109,676 KB
実行使用メモリ 23,712 KB
最終ジャッジ日時 2023-10-12 08:55:27
合計ジャッジ時間 4,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 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.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

class Program
{
    static readonly int Threshold = 4;

    public void Solve()
    {
        int H = Reader.Int(), W = Reader.Int();
        var Prob = Reader.IntTable(H).Select(r => r.Select(c => c / 100.0).ToArray()).ToArray();
        var Val = Reader.IntTable(H).Select(r => r.Select(c => Threshold - c).ToArray()).ToArray();
        var dp = new double[1 << W];
        dp[0] = 1;
        double ans = 0;

        for (int r = 0; r < H; r++)
        {
            var nextdp = new double[1 << W];
            for (int prevMask = 0; prevMask < (1 << W); prevMask++)
                if (dp[prevMask] > 0)
                    for (int currMask = 0; currMask < (1 << W); currMask++)
                    {
                        double p = dp[prevMask];
                        for (int c = 0; c < W; c++)
                            if ((currMask >> c & 1) == 1) p *= Prob[r][c];
                            else p *= 1 - Prob[r][c];
                        int atLast = Simulate(Val, r, prevMask, currMask);
                        ans += p * BitCount32(atLast);
                        nextdp[atLast] += p;
                    }
            dp = nextdp;
        }

        Console.WriteLine(ans);
    }

    private static int Simulate(int[][] Val, int r, int prevMask, int currMask)
    {
        int W = Val[0].Length;
        int[] pt = new int[W];
        var who = new List<int>();
        int stands = 0;
        Action<int, List<int>> Add = (w, list) => { stands += 1 << w; list.Add(w); };

        for (int c = 0; c < W; c++)
        {
            if (r > 0) pt[c] = prevMask >> c & 1;
            pt[c] += Val[r][c] * (currMask >> c & 1);
            if (pt[c] >= Threshold) Add(c, who);
        }
        while (who.Count > 0)
        {
            var nextWho = new List<int>();
            foreach (int c in who)
            {
                if (c - 1 >= 0 && ++pt[c - 1] == Threshold) Add(c - 1, nextWho);
                if (c + 1 < W && ++pt[c + 1] == Threshold) Add(c + 1, nextWho);
            }
            who = nextWho;
        }

        return stands;
    }

    static int BitCount32(int x)
    {
        x -= x >> 1 & 0x55555555;
        x = (x & 0x33333333) + (x >> 2 & 0x33333333);
        return ((x + (x >> 4) & 0x0f0f0f0f) * 0x01010101) >> 24;
    }

}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0