-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path086.swift
More file actions
62 lines (56 loc) · 1.21 KB
/
086.swift
File metadata and controls
62 lines (56 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
ビットごとに独立していて処理して構わないのでそうする
ビットごとに
- 0になるべきAx
- 1になるべき3つのAxの組み合わせ
の制約を整理する
そのビットのみのAxの組み合わせ(約4000)を制約と照らし合わせる。
例
入力
A1 A2 A3で12
制約
- 0ビット(1を担当)はA1 A2 A3すべてでOFF
- 2ビット(4を担当)はA1 A2 A3のどれかがON
など
*/
func readIntArray() -> [Int] {
readLine()!.split(separator: " ").map { Int(String($0))! }
}
let nq = readIntArray()
let n = nq[0]
let q = nq[1]
//r: restriction
var rOn = [[Int]](repeating: [], count: 60)
var rOff = [Int](repeating: 0, count: 60)
for _ in 1...q {
let input = readIntArray()
let w = input[3]
let source = (Int(1) << (input[0] - 1))
| (1 << (input[1] - 1))
| (1 << (input[2] - 1))
for i in 0...59 {
if w & (1 << i) == 0 {
rOff[i] |= source
} else {
rOn[i].append(source)
}
}
}
var ans = 1
for i in 0...59 {
var counter = 0
search:
for j in 0..<(1 << n) {
if rOff[i] & j != 0 {
continue search
}
for r in rOn[i] {
if j & r == 0 {
continue search
}
}
counter += 1
}
ans = (ans * counter) % 1000000007
}
print(ans)