結果

問題 No.1340 おーじ君をさがせ
ユーザー maguroflymagurofly
提出日時 2021-01-19 15:43:19
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 11,520 KB
実行使用メモリ 21,904 KB
最終ジャッジ日時 2023-08-22 13:17:57
合計ジャッジ時間 10,714 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,364 KB
testcase_01 AC 76 ms
15,268 KB
testcase_02 AC 76 ms
15,096 KB
testcase_03 AC 76 ms
15,144 KB
testcase_04 WA -
testcase_05 AC 76 ms
15,268 KB
testcase_06 WA -
testcase_07 AC 77 ms
15,156 KB
testcase_08 AC 76 ms
15,144 KB
testcase_09 AC 76 ms
15,180 KB
testcase_10 AC 96 ms
15,404 KB
testcase_11 TLE -
testcase_12 WA -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class BitAndOrSquareMatrix
    attr_reader :rows, :n
    def initialize(*rows)
        @rows, @n = rows, rows.size
    end
    
    def [](i, j)
        @rows[i][j]
    end
    
    def *(other)
        BitAndOrSquareMatrix.new(*(0 ... @n).map { |i|
            (0 ... @n).map { |j|
                (0 ... @n).inject(0) { |prod, k| prod | self[i, k] & other[k, j] }
            }
        })
    end
    
    def **(e)
        x = self
        r = BitAndOrSquareMatrix.new(*(0 ... @n).map { |i| (0 ... @n).map { |j| (i == j) ? 1 : 0 } })
        while e > 0
            r *= x if e.odd?
            x *= x
            e >>= 1
        end
        r
    end
end

N, M, T = gets.split.map(&:to_i)
rows = Array.new(N) { [0] * N }
M.times do
    a, b = gets.split.map { |s| s.to_i - 1 }
    rows[b][a] = 1
end
matrix = BitAndOrSquareMatrix.new(*rows)
result = matrix ** T

puts (0 ... N).sum { |i| result[i, 0] }
0