結果

問題 No.1340 おーじ君をさがせ
ユーザー maguroflymagurofly
提出日時 2021-01-19 23:24:04
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 26,748 KB
最終ジャッジ日時 2023-08-22 18:59:11
合計ジャッジ時間 10,284 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,252 KB
testcase_01 AC 80 ms
15,200 KB
testcase_02 AC 80 ms
15,080 KB
testcase_03 AC 80 ms
15,248 KB
testcase_04 WA -
testcase_05 AC 80 ms
15,088 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 78 ms
15,292 KB
testcase_09 AC 79 ms
15,300 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 93 ms
18,648 KB
testcase_14 AC 112 ms
23,552 KB
testcase_15 AC 87 ms
16,536 KB
testcase_16 WA -
testcase_17 AC 85 ms
15,940 KB
testcase_18 AC 93 ms
18,628 KB
testcase_19 AC 84 ms
15,192 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 94 ms
15,256 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 90 ms
15,404 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 160 ms
24,376 KB
testcase_33 AC 160 ms
24,524 KB
testcase_34 AC 161 ms
24,852 KB
testcase_35 WA -
testcase_36 AC 83 ms
15,092 KB
testcase_37 AC 95 ms
15,292 KB
testcase_38 AC 101 ms
16,308 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 82 ms
15,104 KB
testcase_45 AC 82 ms
15,016 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 81 ms
15,084 KB
testcase_61 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class BitAndOrMatrix
  attr_reader :n, :bits
  def initialize(n, bits)
    @n, @bits = n, bits
    @u = (1 << n) - 1
    @v = ((@u + 1)**n - 1) / @u
  end

  def self.rows(rows)
    n, bits = rows.size, 0
    rows.each_with_index do |row, i|
      x = 0
      row.each_with_index do |a, j|
        x |= a << j
      end
      bits |= x << n * i
    end
    new(n, bits)
  end

  def self.id(n)
    new(n, ((1 << (n + 1) * n) - 1) / ((1 << n + 1) - 1))
  end

  def [](i, j)
    @bits >> i * @n + j & 1
  end

  def +(other)
    self.class.new(@n, @bits | other.bits)
  end

  def *(other)
    a, b = @bits, other.bits
    bits = 0
    while a > 0 and b > 0
      bits ^= ((a & @v) * @u) & ((b & @u) * @v)
      a >>= 1
      b >>= n
    end
    self.class.new(@n, bits)
  end

  def **(e)
    r = self.class.id(@n)
    x = self
    while e > 0
      r *= x if (e & 1) == 1
      x *= x
      e >>= 1
    end
    r
  end

  def to_a
    (0 ... @n).map { |i| (0 ... @n).map { |j| self[i, j] } }
  end
end

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

ans = BitAndOrMatrix.rows(rows) ** T
#STDERR.puts ans.to_a.map(&:inspect)
puts ans.to_a[0].sum
0