From c29e4e153d560d7ab8a1a532f42f69ee7139abb1 Mon Sep 17 00:00:00 2001 From: ikjo93 <82401504+ikjo93@users.noreply.github.com> Date: Sat, 19 Nov 2022 19:53:49 +0900 Subject: [PATCH 1/2] Create 20221119.java --- "\354\235\265\354\241\260/20221119.java" | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "\354\235\265\354\241\260/20221119.java" diff --git "a/\354\235\265\354\241\260/20221119.java" "b/\354\235\265\354\241\260/20221119.java" new file mode 100644 index 0000000..9886c9a --- /dev/null +++ "b/\354\235\265\354\241\260/20221119.java" @@ -0,0 +1,55 @@ +class Solution { + + final int MOD = 20170805; + + public int solution(int m, int n, int[][] cityMap) { + int[][][] sum = new int[m][n][3]; // 0일 경우 : 0, 2일 경우 오른쪽 : 1, 2일 경우 아래 : 2 + for (int i = 1; i < n; i++) { + if (cityMap[0][i] != 1) { + sum[0][i][0] = 1; + } else { + break; + } + } + + for (int i = 1; i < m; i++) { + if (cityMap[i][0] != 1) { + sum[i][0][0] = 1; + } else { + break; + } + } + + for (int i = 1; i < m; i++) { + for (int j = 1; j < n; j++) { + if (cityMap[i][j] == 0) { + if (cityMap[i - 1][j] == 0) { + sum[i][j][0] = (sum[i][j][0] + sum[i - 1][j][0]) % MOD; + } else if (cityMap[i - 1][j] == 2) { + sum[i][j][0] = (sum[i][j][0] + sum[i - 1][j][2]) % MOD; + } + + if (cityMap[i][j - 1] == 0) { + sum[i][j][0] = (sum[i][j][0] + sum[i][j - 1][0]) % MOD; + } else if (cityMap[i][j - 1] == 2) { + sum[i][j][0] = (sum[i][j][0] + sum[i][j - 1][1]) % MOD; + } + } else if (cityMap[i][j] == 2) { + if (cityMap[i - 1][j] == 0) { + sum[i][j][2] = (sum[i][j][2] + sum[i - 1][j][0]) % MOD; + } else if (cityMap[i - 1][j] == 2) { + sum[i][j][2] = (sum[i][j][2] + sum[i - 1][j][2]) % MOD; + } + + if (cityMap[i][j - 1] == 0) { + sum[i][j][1] = (sum[i][j][1] + sum[i][j - 1][0]) % MOD; + } else if (cityMap[i][j - 1] == 2) { + sum[i][j][1] = (sum[i][j][1] + sum[i][j - 1][1]) % MOD; + } + } + } + } + + return sum[m - 1][n - 1][0] % MOD; + } +} From ab97c0438232b25d0b632e178ad77257374db699 Mon Sep 17 00:00:00 2001 From: ikjo93 <82401504+ikjo93@users.noreply.github.com> Date: Sat, 19 Nov 2022 20:50:23 +0900 Subject: [PATCH 2/2] Update 20221119.java --- "\354\235\265\354\241\260/20221119.java" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\354\235\265\354\241\260/20221119.java" "b/\354\235\265\354\241\260/20221119.java" index 9886c9a..bfed229 100644 --- "a/\354\235\265\354\241\260/20221119.java" +++ "b/\354\235\265\354\241\260/20221119.java" @@ -50,6 +50,6 @@ public int solution(int m, int n, int[][] cityMap) { } } - return sum[m - 1][n - 1][0] % MOD; + return sum[m - 1][n - 1][0]; } }