Skip to content

Instantly share code, notes, and snippets.

@matsueushi
Created March 20, 2022 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsueushi/138b0ba7a40e21c189ded0a88f7d35bc to your computer and use it in GitHub Desktop.
Save matsueushi/138b0ba7a40e21c189ded0a88f7d35bc to your computer and use it in GitHub Desktop.
function solve(n, m, ts, xss, ss)
mat = BitArray(undef, n, m)
for i in 1:n
for j in 1:ts[i]
mat[i, xss[i][j]] = 1
end
end
println(mat)
s = BitArray(ss)
c = 1
for i in 1:m
for j in c:n
if mat[j, i] == 1
if s[i] == 1
s .⊻= mat[j, :]
end
mat[j, :], mat[c, :] = mat[c, :], mat[j, :]
c += 1
break
end
end
end
end
function main()
n, m, ts, xss, ss = (9, 8, [4, 5, 8, 5, 1, 4, 8, 2, 2], [[1, 2, 3, 4], [1, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 5, 7], [4], [1, 5, 6, 8], [1, 2, 3, 4, 5, 6, 7, 8], [2, 4], [1, 8]], Bool[1, 1, 0, 1, 0, 0, 0, 1])
println(solve(n, m, ts, xss, ss))
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment