結果
問題 | No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率 |
ユーザー | kakel-san |
提出日時 | 2021-06-13 17:22:32 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 605 ms / 2,000 ms |
コード長 | 3,582 bytes |
コンパイル時間 | 13,518 ms |
コンパイル使用メモリ | 166,820 KB |
実行使用メモリ | 33,280 KB |
最終ジャッジ日時 | 2024-06-02 09:48:06 |
合計ジャッジ時間 | 23,107 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
30,336 KB |
testcase_01 | AC | 54 ms
30,056 KB |
testcase_02 | AC | 76 ms
30,720 KB |
testcase_03 | AC | 57 ms
29,952 KB |
testcase_04 | AC | 55 ms
30,592 KB |
testcase_05 | AC | 60 ms
30,208 KB |
testcase_06 | AC | 55 ms
30,208 KB |
testcase_07 | AC | 57 ms
30,580 KB |
testcase_08 | AC | 54 ms
30,336 KB |
testcase_09 | AC | 56 ms
30,208 KB |
testcase_10 | AC | 56 ms
30,580 KB |
testcase_11 | AC | 55 ms
30,208 KB |
testcase_12 | AC | 55 ms
29,952 KB |
testcase_13 | AC | 148 ms
31,104 KB |
testcase_14 | AC | 112 ms
30,848 KB |
testcase_15 | AC | 81 ms
30,592 KB |
testcase_16 | AC | 95 ms
31,104 KB |
testcase_17 | AC | 97 ms
30,976 KB |
testcase_18 | AC | 96 ms
30,720 KB |
testcase_19 | AC | 65 ms
30,848 KB |
testcase_20 | AC | 345 ms
32,128 KB |
testcase_21 | AC | 84 ms
30,720 KB |
testcase_22 | AC | 57 ms
30,336 KB |
testcase_23 | AC | 587 ms
33,024 KB |
testcase_24 | AC | 587 ms
33,024 KB |
testcase_25 | AC | 600 ms
33,256 KB |
testcase_26 | AC | 583 ms
33,024 KB |
testcase_27 | AC | 588 ms
33,280 KB |
testcase_28 | AC | 584 ms
33,152 KB |
testcase_29 | AC | 605 ms
32,896 KB |
testcase_30 | AC | 593 ms
33,024 KB |
testcase_31 | AC | 588 ms
33,024 KB |
testcase_32 | AC | 592 ms
32,896 KB |
testcase_33 | AC | 569 ms
33,152 KB |
testcase_34 | AC | 93 ms
30,976 KB |
testcase_35 | AC | 91 ms
30,848 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (98 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System; using System.Collections.Generic; using static System.Console; using System.Linq; class yc299 { static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NMap(int n) => Enumerable.Repeat<int>(0, n).Select(_ => NList).ToArray(); static void Main() { var x = NList; var y = NList; var k = NList[0]; var (ma, na, s) = (x[0], x[1], x[2]); var (mb, nb, t) = (y[0], y[1], y[2]); var key = 998244353; var revna = PowMod(na, key - 2, key); var revnb = PowMod(nb, key - 2, key); var amap = AMap(s + t + 1, ma, revna, key); var bmap = BMap(s + t + 1, mb, revnb, key); var nmap = Mul(bmap, amap, key); var dp = new long[s + t + 1]; dp[t] = 1; var tmp = k; while (tmp > 0) { if (tmp % 2 == 1) { dp = Mul(nmap, dp, key); } nmap = Mul(nmap, nmap, key); tmp >>= 1; } WriteLine(dp.Last()); WriteLine(dp[0]); } static long[,] AMap(int size, int ma, int revna, int key) { var amap = new long[size, size]; amap[0, 0] = 1; amap[size - 1, size - 1] = 1; for (var y = 1; y < size - 1; ++y) { var poss = (long)ma * revna % key; var val = 1L; var rev = (1 + key - poss) % key; for (var x = y; x < size - 1; ++x) { amap[x, y] = val * rev % key; val = (val * ma % key) * revna % key; } amap[size - 1, y] = val; } return amap; } static long[,] BMap(int size, int mb, int revnb, int key) { var bmap = new long[size, size]; bmap[0, 0] = 1; bmap[size - 1, size - 1] = 1; for (var y = size - 2; y > 0; --y) { var poss = (long)mb * revnb % key; var val = 1L; var rev = (1 + key - poss) % key; for (var x = y; x > 0; --x) { bmap[x, y] = val * rev % key; val = (val * mb % key) * revnb % key; } bmap[0, y] = val; } return bmap; } static long[,] Mul(long[,] a, long[,] b, int key) { var h = a.GetLength(0); var w = b.GetLength(1); var cm = a.GetLength(1); var map = new long[h, w]; for (var i = 0; i < h; ++i) { for (var j = 0; j < w; ++j) { for (var c = 0; c < cm; ++c) { map[i, j] = (map[i, j] + a[i, c] * b[c, j]) % key; } } } return map; } static long[] Mul(long[,] a, long[] list, int key) { var len = a.GetLength(0); var res = new long[len]; for (var i = 0; i < len; ++i) for (var j = 0; j < list.Length; ++j) { res[i] = (res[i] + a[i, j] * list[j]) % key; } return res; } static int PowMod(int n, int p, int keyNum) { long _n = n % keyNum; var _p = p; var result = 1L; if ((_p & 1) == 1) { result *= _n; } while (_p > 0) { _n = _n * _n % keyNum; _p >>= 1; if ((_p & 1) == 1) { result = (result * _n) % keyNum; } } return (int)result; } }