結果
問題 | No.2156 ぞい文字列 |
ユーザー | 👑 kakel-san |
提出日時 | 2023-09-05 22:00:25 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,805 bytes |
コンパイル時間 | 1,529 ms |
コンパイル使用メモリ | 67,532 KB |
実行使用メモリ | 24,740 KB |
最終ジャッジ日時 | 2023-09-05 22:00:29 |
合計ジャッジ時間 | 3,578 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
22,704 KB |
testcase_01 | AC | 55 ms
20,648 KB |
testcase_02 | AC | 55 ms
20,668 KB |
testcase_03 | AC | 56 ms
22,776 KB |
testcase_04 | AC | 56 ms
20,760 KB |
testcase_05 | AC | 56 ms
22,724 KB |
testcase_06 | AC | 59 ms
20,736 KB |
testcase_07 | AC | 56 ms
24,740 KB |
testcase_08 | AC | 56 ms
20,736 KB |
testcase_09 | AC | 56 ms
20,648 KB |
testcase_10 | AC | 56 ms
20,732 KB |
testcase_11 | AC | 56 ms
20,860 KB |
testcase_12 | AC | 55 ms
22,716 KB |
testcase_13 | AC | 55 ms
22,824 KB |
testcase_14 | AC | 55 ms
20,776 KB |
testcase_15 | AC | 55 ms
22,676 KB |
testcase_16 | AC | 56 ms
22,816 KB |
testcase_17 | AC | 55 ms
22,764 KB |
testcase_18 | AC | 56 ms
20,840 KB |
testcase_19 | AC | 56 ms
22,740 KB |
ソースコード
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(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = long.Parse(ReadLine()); var a = new long[][] { new long[] { 1 }, new long[] { 0 } }; var x = new long[][] { new long[] { 1, 1 }, new long[] { 1, 0 } }; var b = Matrix.Mul(Matrix.Pow(x, n - 1), a); WriteLine((b[0][0] + b[1][0] + mod - 1) % mod); } static int mod = 998_244_353; class Matrix { // 行列の累乗 public static long[][] Pow(long[][] m, long k) { var multi = m; var r = new long[m.Length][]; for (var i = 0; i < m.Length; ++i) { r[i] = new long[m.Length]; r[i][i] = 1; } while (k > 0) { if ((k & 1) == 1) r = Mul(r, multi); multi = Mul(multi, multi); k >>= 1; } return r; } // 行列の積 public static long[][] Mul(long[][] x, long[][] y) { var r = new long[x.Length][]; for (var i = 0; i < x.Length; ++i) r[i] = new long[y[0].Length]; for (var i = 0; i < x.Length; ++i) for (var k = 0; k < x[0].Length; ++k) { for (var j = 0; j < y[0].Length; ++j) r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % mod; } return r; } } }