From 3eeab58fc880e5561325f7ce77d80bc99ae7c1c6 Mon Sep 17 00:00:00 2001 From: SSOOYA Date: Thu, 26 Oct 2023 13:59:51 +0900 Subject: [PATCH] =?UTF-8?q?unsolve/#173:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=98=EB=A8=B8=EC=8A=A4=20=ED=8C=8C=EA=B4=B4=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EA=B1=B4=EB=AC=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\235\200 \352\261\264\353\254\274.swift" | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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 +}