diff --git "a/AlgorithmReview/Programmers/Lv3/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.swift" "b/AlgorithmReview/Programmers/Lv3/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.swift" index 48bd3e7..b4d4580 100644 --- "a/AlgorithmReview/Programmers/Lv3/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.swift" +++ "b/AlgorithmReview/Programmers/Lv3/\355\214\214\352\264\264\353\220\230\354\247\200 \354\225\212\354\235\200 \352\261\264\353\254\274.swift" @@ -7,7 +7,7 @@ import Foundation -func solution(_ board:[[Int]], _ skill:[[Int]]) -> Int { +func timeout(_ board:[[Int]], _ skill:[[Int]]) -> Int { let (row, col) = (board.count, board[0].count) @@ -31,3 +31,44 @@ func solution(_ board:[[Int]], _ skill:[[Int]]) -> Int { } return ans } + +func reference(_ board:[[Int]], _ skill:[[Int]]) -> Int { + + let (row, col) = (board.count, board[0].count) + var temp = [[Int]](repeating: [Int](repeating: 0, count: col+1), count: row+1) + + for s in skill { + let (type, r1, c1, r2, c2) = (s[0], s[1], s[2], s[3], s[4]) + let degree = type == 2 ? s[5] : -s[5] + temp[r1][c1] += degree + temp[r1][c2+1] += -degree + temp[r2+1][c1] += -degree + temp[r2+1][c2+1] += degree + } + + // 행 기준 누적합 + for i in 0.. 0{ + ans += 1 + } + } + } + return ans +}