ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2630
// ์ฟผ๋ํธ๋ฆฌ๋ฅผ ๋ง๋๋ ๋ฌธ์
package main
import (
"bufio"
"fmt"
"os"
)
var (
paper [][]int
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
paper = make([][]int, n)
for i := range paper {
paper[i] = make([]int, n)
}
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
fmt.Fscanf(reader, "%d ", &paper[i][j])
}
}
blue, white := checkPart(0, 0, n, 0, 0)
fmt.Fprintln(writer, white)
fmt.Fprintln(writer, blue)
}
func checkPart(row, col, n, blue, white int) (int, int) {
first := paper[row][col]
var isPaper bool = true
for i := row; i < row+n; i++ {
for j := col; j < col+n; j++ {
if i == row && j == col {
continue
}
if paper[i][j] != first {
isPaper = false
break
}
}
if !isPaper {
break
}
}
if isPaper {
if first == 1 {
blue++
} else {
white++
}
return blue, white
}
interval := n / 2
blue, white = checkPart(row, col, interval, blue, white)
blue, white = checkPart(row+interval, col, interval, blue, white)
blue, white = checkPart(row, col+interval, interval, blue, white)
blue, white = checkPart(row+interval, col+interval, interval, blue, white)
return blue, white
}
๐จ Python3
# https://www.acmicpc.net/problem/2630
# ์ฟผ๋ํธ๋ฆฌ๋ฅผ ๋ง๋๋ ๋ฌธ์
import sys
paper = []
def check_part(row, col, n, blue, white):
global paper
first = paper[row][col]
is_paper = True
for i in range(row, row+n):
for j in range(col, col+n):
if i == row and j == col:
continue
if paper[i][j] != first:
is_paper = False
break
if not is_paper:
break
if is_paper:
if first == 1:
blue += 1
else:
white += 1
return blue, white
interval = n//2
blue, white = check_part(row, col, interval, blue, white)
blue, white = check_part(row+interval, col, interval, blue, white)
blue, white = check_part(row, col+interval, interval, blue, white)
blue, white = check_part(row+interval, col+interval, interval, blue, white)
return blue, white
if __name__ == "__main__":
n = int(sys.stdin.readline())
for i in range(n):
paper.append(list(map(int, sys.stdin.readline().split())))
blue, white = check_part(0, 0, n, 0, 0)
print(white)
print(blue)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1780๋ฒ / ์ข ์ด์ ๊ฐ์ [Go][Python3] (0) | 2020.12.30 |
---|---|
BOJ / 1992๋ฒ / ์ฟผ๋ํธ๋ฆฌ [Go][Python3] (0) | 2020.12.29 |
BOJ / 5635๋ฒ / ์์ผ [Go][Python3] (0) | 2020.12.27 |
BOJ / 3182๋ฒ / ํ๋์ด๋ ๊ณต๋ถ๊ฐ ํ๊ธฐ ์ซ์ด! [Go][Python3] (0) | 2020.12.26 |
BOJ / 10708๋ฒ / ํฌ๋ฆฌ์ค๋ง์ค ํํฐ [Go][Python3] (0) | 2020.12.25 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ฐ๋
- Macbook pro 2012 mid 13
- MongoDB
- python3
- ๋ฐฑ์ค
- ์คํ
- BOJ
- baekjoon
- ๋ชฝ๊ณ ๋๋น
- Golang
- ballet
- dp
- ํ
- Algorithm
- ๋ถํ ์ ๋ณต
- ๋งฅ๋ถ
- go
- ์๋ฐ
- ๋งฅ๋ถํ๋ก
- ํด์๋งต
- ์๊ณ ๋ฆฌ์ฆ
- AWS
- dfs
- java
- ์๊ฐ๊ต์ฒด
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ธ๋ฃจํธํฌ์ค
- BFS
- ์ด๋ถํ์
- Total
- Today
- Yesterday