結果
問題 | No.463 魔法使いのすごろく🎲 |
ユーザー | 37zigen |
提出日時 | 2016-12-15 13:28:53 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 205 ms / 2,000 ms |
コード長 | 2,621 bytes |
コンパイル時間 | 4,409 ms |
コンパイル使用メモリ | 88,216 KB |
実行使用メモリ | 55,396 KB |
最終ジャッジ日時 | 2024-05-07 14:50:39 |
合計ジャッジ時間 | 10,860 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 144 ms
54,392 KB |
testcase_01 | AC | 141 ms
54,428 KB |
testcase_02 | AC | 153 ms
54,332 KB |
testcase_03 | AC | 136 ms
54,352 KB |
testcase_04 | AC | 146 ms
54,476 KB |
testcase_05 | AC | 164 ms
54,464 KB |
testcase_06 | AC | 136 ms
54,260 KB |
testcase_07 | AC | 135 ms
53,944 KB |
testcase_08 | AC | 152 ms
54,540 KB |
testcase_09 | AC | 193 ms
54,752 KB |
testcase_10 | AC | 154 ms
54,476 KB |
testcase_11 | AC | 154 ms
54,416 KB |
testcase_12 | AC | 152 ms
54,580 KB |
testcase_13 | AC | 122 ms
53,908 KB |
testcase_14 | AC | 159 ms
54,624 KB |
testcase_15 | AC | 158 ms
54,544 KB |
testcase_16 | AC | 136 ms
54,260 KB |
testcase_17 | AC | 149 ms
54,032 KB |
testcase_18 | AC | 134 ms
54,268 KB |
testcase_19 | AC | 143 ms
54,552 KB |
testcase_20 | AC | 136 ms
54,284 KB |
testcase_21 | AC | 188 ms
54,640 KB |
testcase_22 | AC | 205 ms
55,196 KB |
testcase_23 | AC | 172 ms
54,568 KB |
testcase_24 | AC | 191 ms
54,892 KB |
testcase_25 | AC | 194 ms
54,616 KB |
testcase_26 | AC | 168 ms
54,352 KB |
testcase_27 | AC | 179 ms
54,508 KB |
testcase_28 | AC | 195 ms
55,396 KB |
testcase_29 | AC | 168 ms
54,600 KB |
testcase_30 | AC | 189 ms
54,900 KB |
testcase_31 | AC | 197 ms
54,892 KB |
testcase_32 | AC | 193 ms
54,624 KB |
testcase_33 | AC | 169 ms
54,524 KB |
testcase_34 | AC | 162 ms
54,608 KB |
testcase_35 | AC | 134 ms
54,364 KB |
testcase_36 | AC | 136 ms
54,124 KB |
testcase_37 | AC | 138 ms
54,272 KB |
testcase_38 | AC | 125 ms
54,032 KB |
ソースコード
package yukicoder; import java.util.*; public class Q463 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); double[] c = new double[n]; for (int i = 1; i < n - 1; ++i) { c[i] = sc.nextDouble(); } // 魔法を使わずにマスi(0<=i<n-1)からn-1まで行くのに必要な回数の期待値 double[] dp1 = new double[n]; // A(Evec+a)=Evec // (A-E)x=-Aa double[][] mx = new double[n - 1][n - 1]; for (int i = 0; i < n - 1; ++i) { double p = 1.0 / m; for (int j = 1; j <= m; ++j) { if (i + j < n - 1) { mx[i][i + j] += p; } else if (i + j == n - 1) { continue; } else { int pos = (n - 1) - ((i + j) - (n - 1)); mx[i][pos] += p; } } } double[] v = new double[n - 1]; for (int i = 0; i < n - 1; ++i) { v[i] = -c[i]; } v = mul(mx, v); for (int i = 0; i < n - 1; ++i) { mx[i][i] -= 1; } // [mx]x=vをxについて解きたい. for (int i = 0; i < n - 1; ++i) { int pos = i; while (pos < n - 1 && mx[pos][i] == 0) { ++pos; } if (pos == n - 1) continue; double[] tmp = mx[i]; mx[i] = mx[pos]; mx[pos] = tmp; double tmp3 = v[i]; v[i] = v[pos]; v[pos] = tmp3; double tmp2 = mx[i][i]; for (int j = 0; j < n - 1; ++j) { mx[i][j] /= tmp2; } v[i] /= tmp2; for (int j = 0; j < n - 1; ++j) { if (mx[j][i] == 0) continue; if (j == i) continue; double tmp4 = mx[j][i]; for (int k = 0; k < n - 1; ++k) { mx[j][k] -= mx[i][k] * tmp4; } v[j] -= v[i] * tmp4; } } double[] e = new double[n]; Arrays.fill(e, Double.MAX_VALUE); e[n - 1] = 0; outer: for (int i = n - 2; i >= 0; --i) { double e1 = 0; for (int j = m; j >= 1; --j) { if (i + j >= n - 1) { e[i] = 0; continue outer; } else { e1 += 1.0 / m * (e[i + j] + c[i + j]); } } double e2 = 1L << 60; for (int j = m; j >= 1; --j) { e2 = Math.min(e2, v[i + j] + c[i + j]); } e[i] = Math.min(e1, e2); } System.out.printf("%.20f",e[0]); } static void show(double[][] mx) { int n = mx.length; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { System.out.print(mx[i][j] + " "); } System.out.println(); } } static double[] mul(double[][] a, double[] v) { int n = a.length; double[] ret = new double[n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { ret[i] += a[i][j] * v[j]; } } return ret; } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }