結果

問題 No.803 Very Limited Xor Subset
ユーザー ikdikd
提出日時 2019-03-18 15:19:38
言語 Nim
(2.0.2)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 3,107 ms
コンパイル使用メモリ 69,252 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 15:28:37
合計ジャッジ時間 5,765 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 7 ms
4,380 KB
testcase_26 AC 6 ms
4,384 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 7 ms
4,456 KB
testcase_32 AC 7 ms
4,384 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 2 ms
4,504 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 4 ms
4,492 KB
testcase_41 AC 4 ms
4,380 KB
testcase_42 AC 4 ms
4,384 KB
testcase_43 AC 4 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

proc gauss(a: var seq[seq[int]]): int =
  let (n, m) = (a.len, a[0].len)
  var rk = 0
  for j in 0..<(m - 1):
    var pv = -1
    for i in rk..<n:
      if a[i][j] == 1:
        pv = i
        break
    if pv >= 0:
      swap(a[rk], a[pv])
      for i in (rk + 1)..<n:
        if a[i][j] == 1:
          for j2 in j..<m:
            a[i][j2] = a[i][j2] xor a[rk][j2]
      rk += 1
  for i in rk..<n:
    if a[i][m - 1] > 0:
      rk = -1
      break
  return rk

proc main() =
  let
    nmx = stdin.readLine.strip.split.map(parseInt)
    (n, m, x) = (nmx[0], nmx[1], nmx[2])
    a = stdin.readLine.strip.split.map(parseInt)
    lrs = (0..<m).mapIt(stdin.readLine.strip.split.map(parseInt))
    b = 33

  var mat = newSeqWith(b + m, newSeq[int](n + 1))
  for i in 0..<b:
    for j in 0..<n:
      if ((a[j] shr i) and 1) == 1:
        mat[i][j] = 1
  for i in 0..<b:
    if ((x shr i) and 1) == 1:
      mat[i][n] = 1
  for i in 0..<m:
    for j in (lrs[i][1] - 1)..(lrs[i][2] - 1):
      mat[b + i][j] = 1
    mat[b + i][n] = lrs[i][0]
  let rk = gauss(mat)
  if rk < 0:
    echo 0
  else:
    var
      ans: int64 = 1
      mo: int64 = 1000000000 + 7
    for _ in 0..<(n - rk):
      ans = ans * 2 mod mo
    echo ans
main()
0