結果
問題 | No.2131 Concon Substrings (COuNt Version) |
ユーザー |
|
提出日時 | 2022-11-26 19:18:47 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 1,095 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-10-03 03:11:58 |
合計ジャッジ時間 | 2,739 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
main = -> {N = gets.to_iA = ModMatrix.new([[25, 0, 0, 0, 0],[1, 25, 0, 1, 0],[0, 1, 25, 0, 0],[0, 0, 1, 25, 0],[0, 0, 1, 0, 26],])x = ModMatrix.new([[1], [0], [0], [0], [0]])B = A**Nputs (B * x)[4, 0]}MOD = 998244353class ModMatrixattr_reader :n, :m, :rowsdef initialize(rows)@n, @m, @rows = rows.size, rows[0].size, rowsenddef self.id(n)new((0 ... n).map { |i|(0 ... n).map { |j| (i == j) ? 1 : 0 }})enddef [](i, j)@rows[i][j]enddef +(other)self.class.new(@rows.map.with_index { |row, i|row.map.with_index { |x, j| (x + other[i, j]) % MOD }})enddef *(other)raise "dimension mismatch" unless @m == other.nself.class.new((0 ... @n).map { |i|(0 ... other.m).map { |j|(0 ... @m).sum { |k| self[i, k] * other[k, j] } % MOD}})enddef **(e)r = self.class.id(@n)x = selfwhile e > 0r *= x if (e & 1) == 1x *= x if e > 1e >>= 1endrendendmain.call