結果
問題 | No.2529 Treasure Hunter |
ユーザー | 👑 kakel-san |
提出日時 | 2023-11-04 20:07:08 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 3,536 bytes |
コンパイル時間 | 10,782 ms |
コンパイル使用メモリ | 156,836 KB |
実行使用メモリ | 186,516 KB |
最終ジャッジ日時 | 2023-11-04 20:07:24 |
合計ジャッジ時間 | 14,023 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
33,324 KB |
testcase_01 | AC | 128 ms
43,748 KB |
testcase_02 | AC | 123 ms
41,732 KB |
testcase_03 | AC | 125 ms
42,436 KB |
testcase_04 | AC | 125 ms
42,436 KB |
testcase_05 | AC | 125 ms
42,368 KB |
testcase_06 | AC | 125 ms
42,360 KB |
testcase_07 | AC | 126 ms
42,444 KB |
testcase_08 | AC | 126 ms
42,436 KB |
testcase_09 | AC | 120 ms
41,152 KB |
testcase_10 | AC | 125 ms
42,364 KB |
testcase_11 | AC | 130 ms
42,328 KB |
testcase_12 | AC | 118 ms
41,776 KB |
testcase_13 | AC | 119 ms
42,040 KB |
testcase_14 | AC | 118 ms
41,968 KB |
testcase_15 | AC | 118 ms
41,920 KB |
testcase_16 | AC | 120 ms
42,152 KB |
testcase_17 | AC | 119 ms
42,008 KB |
testcase_18 | AC | 120 ms
41,904 KB |
testcase_19 | AC | 121 ms
42,120 KB |
testcase_20 | AC | 119 ms
42,048 KB |
testcase_21 | AC | 120 ms
42,152 KB |
testcase_22 | AC | 119 ms
186,516 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (234 ms)。 MSBuild のバージョン 17.7.3+8ec440e68 (.NET) main -> /home/judge/data/code/bin/Release/net7.0/main.dll main -> /home/judge/data/code/bin/Release/net7.0/publish/
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var c = NList; var (w, h) = (c[0], c[1]); ans[u] = Treasure(h, w); } WriteLine(string.Join("\n", ans)); } static int mod = 998_244_353; static int rev2 = 499_122_177; static long Treasure(int h, int w) { var dp = new long[3]; dp[0] = 1; for (var i = 0; i < h; ++i) { var ndp = new long[3]; ndp[0] = (dp[0] + dp[1] + dp[2]) % mod; if (w == 1) { ndp[1] = dp[0]; } else if (w == 2) { ndp[1] = (dp[0] * 2 + dp[1]) % mod; } else if (w == 3) { ndp[1] = (dp[0] * 3 + dp[1] * 2) % mod; } else { ndp[1] = (dp[0] * w + dp[1] * (w - 1) + dp[2] * (w - 2)) % mod; ndp[2] = (dp[0] * ((long)w % mod * (w - 1) % mod * rev2 % mod + mod - w) + dp[1] * ((long)(w - 1) % mod * (w - 2) % mod * rev2 % mod + mod - w + 2) + dp[2] * ((long)(w - 2) % mod * (w - 3) % mod * rev2 % mod + mod - w + 4)) % mod; } dp = ndp; } return (dp[0] + dp[1] + dp[2]) % mod; } class NCR { int[] facts; int[] revFacts; int mod; public NCR(int n, int mod) { facts = new int[n + 1]; revFacts = new int[n + 1]; this.mod = mod; facts[0] = 1; var tmp = 1L; for (var i = 1; i <= n; ++i) { tmp = (tmp * i) % mod; facts[i] = (int)tmp; } tmp = Exp(facts[n], mod - 2); revFacts[n] = (int)tmp; for (var i = n; i > 1; --i) { tmp = (tmp * i) % mod; revFacts[i - 1] = (int)tmp; } revFacts[0] = 1; } public long Exp(long n, long k) { n = n % mod; if (k == 0) return 1; if (k == 1) return n; var half = Exp(n, k / 2); var result = (half * half) % mod; return ((k % 2) == 0) ? result : ((result * n) % mod); } public long Calc(int n, int r) { return (long)facts[n] * revFacts[r] % mod * revFacts[n - r] % mod; } /// <summary>nが大きくrが小さい場合の計算</summary> public long Calc2(int n, int r) { var tmp = 1L; for (var i = 0; i < r; ++i) { tmp = tmp * (n - i) % mod; } return tmp * revFacts[r] % mod; } public long NPR(int n, int r) { return (long)facts[n] * revFacts[r] % mod; } public long Fact(int n) { return facts[n]; } public long RevFact(int n) { return revFacts[n]; } } }