-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path079.swift
More file actions
49 lines (44 loc) · 735 Bytes
/
079.swift
File metadata and controls
49 lines (44 loc) · 735 Bytes
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
func readIntArray() -> [Int] {
readLine()!.split(separator: " ").map { Int(String($0))! }
}
let hw = readIntArray()
let h = hw[0]
let w = hw[1]
var a: [[Int]] = []
var b: [[Int]] = []
for _ in 1...h {
a.append(readIntArray())
}
for _ in 1...h {
b.append(readIntArray())
}
var counter = 0
var result = true
for i in 0...h - 2 {
for j in 0...w - 2 {
let diff = b[i][j] - a[i][j]
counter += abs(diff)
a[i][j] += diff
a[i][j + 1] += diff
a[i + 1][j] += diff
a[i + 1][j + 1] += diff
}
if a[i][w - 1] != b[i][w - 1] {
result = false
break
}
}
if result {
for j in 0...w - 1 {
if a[h - 1][j] != b[h - 1][j] {
result = false
break
}
}
}
if result {
print("Yes")
print(counter)
} else {
print("No")
}