-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path057.swift
More file actions
65 lines (58 loc) · 1.29 KB
/
057.swift
File metadata and controls
65 lines (58 loc) · 1.29 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
63
64
65
func readInt() -> Int {
Int(readLine()!)!
}
func readInts() -> [Int] {
readLine()!.split(separator: " ").map { Int(String($0))! }
}
let nm = readInts()
let n = nm[0] //スイッチ数
let m = nm[1] //パネル数
var t = [[Bool]](repeating: [Bool](repeating: false, count: m), count: n)
for s in 0..<n {
_ = readLine()!
let pp = readInts()
for p in pp {
t[s][p - 1] = true
}
}
var target: [Bool] = readInts().map { $0 == 1 }
var newSwPos = 0
for p in 0..<m {
var found = false
for s in newSwPos..<n {
if t[s][p] {
if s != newSwPos {
let temp = t[s]
t[s] = t[newSwPos]
t[newSwPos] = temp
}
found = true
break
}
}
if found {
for s in newSwPos + 1..<n {
if t[s][p] {
for i in p..<m {
t[s][i] = t[s][i] != t[newSwPos][i]
}
}
}
if target[p] {
for i in p..<m {
target[i] = target[i] != t[newSwPos][i]
}
}
newSwPos += 1
}
}
if let _ = target.first(where: { $0 }) {
print("0")
} else {
var ans = 1
for _ in newSwPos..<n {
ans *= 2
ans %= 998244353
}
print(ans)
}