結果
問題 | No.309 シャイな人たち (1) |
ユーザー | eitaho |
提出日時 | 2015-12-02 18:08:36 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 4,900 bytes |
コンパイル時間 | 2,097 ms |
コンパイル使用メモリ | 111,232 KB |
実行使用メモリ | 40,064 KB |
最終ジャッジ日時 | 2024-09-14 08:00:29 |
合計ジャッジ時間 | 31,643 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3,042 ms
39,936 KB |
testcase_01 | TLE | - |
testcase_02 | AC | 1,509 ms
39,808 KB |
testcase_03 | AC | 3,723 ms
39,808 KB |
testcase_04 | AC | 85 ms
23,944 KB |
testcase_05 | AC | 759 ms
27,648 KB |
testcase_06 | AC | 1,553 ms
39,936 KB |
testcase_07 | AC | 1,644 ms
39,936 KB |
testcase_08 | AC | 3,787 ms
39,936 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 3,674 ms
39,808 KB |
testcase_13 | AC | 36 ms
19,968 KB |
testcase_14 | AC | 36 ms
19,968 KB |
testcase_15 | AC | 396 ms
27,008 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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() { //var sw = Stopwatch.StartNew(); int H = Reader.Int(), W = Reader.Int(); Reader.Line(); var Prob = Reader.IntTable(H).Select(r => r.Select(c => c / 100.0).ToArray()).ToArray(); Reader.Line(); var Val = Reader.IntTable(H).Select(r => r.Select(c => Threshold - c).ToArray()).ToArray(); int[] atLast = Simulate(W); 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 currMask = 0; currMask < (1 << W); currMask++) { double currMaskProb = 1; for (int c = 0; c < W; c++) if ((currMask >> c & 1) == 1) currMaskProb *= Prob[r][c]; else currMaskProb *= 1 - Prob[r][c]; for (int prevMask = 0; prevMask < (1 << W); prevMask++) if (dp[prevMask] > 0) { double p = dp[prevMask] * currMaskProb; int key = 0; for (int c = 0; c < W; c++) { int pt = Val[r][c] * (currMask >> c & 1); if (r > 0) pt += prevMask >> c & 1; key = (key << 2) + Math.Max(0, Math.Min(Threshold, pt) - 1); } int nextMask = atLast[key]; ans += p * BitCount32(nextMask); nextdp[nextMask] += p; } } dp = nextdp; } Console.WriteLine(ans); //Console.WriteLine(sw.ElapsedMilliseconds); //Console.ReadLine(); } private int[] Simulate(int W) { int pow = 1 << W * 2; int[] res = new int[pow]; int[] pt = new int[W]; for (int mask = 0; mask < pow; mask++) { var who = new List<int>(); Action<int, List<int>> Add = (w, list) => { res[mask] += 1 << w; list.Add(w); }; for (int c = W - 1, tmp = mask; c >= 0; c--, tmp >>= 2) { pt[c] = 1 + (tmp & 3); 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 res; } 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; } }