結果
問題 | No.309 シャイな人たち (1) |
ユーザー | uafr_cs |
提出日時 | 2015-12-06 15:42:30 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,708 bytes |
コンパイル時間 | 2,442 ms |
コンパイル使用メモリ | 78,968 KB |
実行使用メモリ | 66,884 KB |
最終ジャッジ日時 | 2024-09-14 15:21:41 |
合計ジャッジ時間 | 16,831 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; public class Main { public static final double EPS = 1e-8; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int R = sc.nextInt(); final int C = sc.nextInt(); double[][] probs = new double[R][C]; for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ probs[i][j] = sc.nextDouble(); } } int[][] shys = new int[R][C]; for(int i = 0; i < R; i++){ for(int j = 0; j < C; j++){ shys[i][j] = sc.nextInt(); } } final int DP_SIZE = 1 << C; double[][] knowns_probs = new double[R][DP_SIZE]; for(int i = 0; i < R; i++){ Arrays.fill(knowns_probs[i], 1); } for(int bit = 0; bit < DP_SIZE; bit++){ for(int r = 0; r < R; r++){ for(int i = 0; i < C; i++){ knowns_probs[r][bit] *= ((bit & (1 << i)) != 0) ? (1.0 - probs[r][i] / 100.0) : (probs[r][i] / 100.0); } } } double[][] DP = new double[R + 1][DP_SIZE]; //配るDPする. Arrays.fill(DP[0], 0); DP[0][0] = 1.0; for(int r = 0; r < R; r++){ // O(R) -> 11 for(int prev_raise_bit = 0; prev_raise_bit < DP_SIZE; prev_raise_bit++){ // O(R * 2^C) -> if(DP[r][prev_raise_bit] < EPS){ continue; } for(int curr_known_bit = 0; curr_known_bit < DP_SIZE; curr_known_bit++) { // O(R * 2^C * 2^C) -> if(knowns_probs[r][curr_known_bit] < EPS){ continue; } int[] curr_line = new int[C]; for(int i = 0; i < C; i++){ if((prev_raise_bit & (1 << i)) != 0){ curr_line[i]++; } } LinkedList<Integer> uppers = new LinkedList<Integer>(); int curr_raise_bit = 0; for(int i = 0; i < C; i++){ if((curr_known_bit & (1 << i)) == 0){ continue; } curr_line[i] += (4 - shys[r][i]); if(curr_line[i] >= 4){ uppers.add(i); curr_raise_bit |= (1 << i); }; } while(!uppers.isEmpty()){ int pos = uppers.poll(); if(curr_line[pos] < 4){ continue; } // raise_up! if(pos > 0 && (curr_raise_bit & (1 << (pos - 1))) == 0){ if(++curr_line[pos - 1] >= 4){ uppers.add(pos - 1); curr_raise_bit |= (1 << (pos - 1));} } if(pos < C - 1 && (curr_raise_bit & (1 << (pos + 1))) == 0){ if(++curr_line[pos + 1] >= 4){ uppers.add(pos + 1); curr_raise_bit |= (1 << (pos + 1));} } } DP[r + 1][curr_raise_bit] += DP[r][prev_raise_bit] * knowns_probs[r][curr_known_bit]; } } } /* for(double[] bits : DP){ System.out.println(Arrays.toString(bits)); } */ double answer = 0; for(int r = 0; r <= R; r++){ for(int bit = 0; bit < DP_SIZE; bit++){ answer += Integer.bitCount(bit) * DP[r][bit]; } } System.out.printf("%.11f\n", answer); } public static class Scanner { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() { try { while (!hasNext()) {tok = new StringTokenizer(br.readLine());} } catch(IOException e){ /* ignore */ } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() { getLine(); return tok.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public void close() { try{ br.close(); } catch (IOException e){ /*ignore*/ } } } }