From dad7b4795c870a5ef11119b70cafd341e1af5fc9 Mon Sep 17 00:00:00 2001 From: froglike6 Date: Tue, 22 Jul 2025 14:01:58 +0900 Subject: [PATCH] 2025-07-22 --- froglike6/README.md | 1 + froglike6/graph_theory/34064.py | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 froglike6/graph_theory/34064.py diff --git a/froglike6/README.md b/froglike6/README.md index 5ea1f20..481fad0 100644 --- a/froglike6/README.md +++ b/froglike6/README.md @@ -23,4 +23,5 @@ | 19차시 | 2025.07.04 | 애드 혹 | [서로소 그래프 게임](https://www.acmicpc.net/problem/34035)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/72| | 20차시 | 2025.07.09 | 조합론 | [암호 만들기](https://www.acmicpc.net/problem/1759)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/77| | 21차시 | 2025.07.14 | 기하학 | [Cows](https://www.acmicpc.net/problem/6850)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/82| + | 22차시 | 2025.07.22 | 그래프 | [밤(Time For The Moon Night)](https://www.acmicpc.net/problem/34064)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/88| --- diff --git a/froglike6/graph_theory/34064.py b/froglike6/graph_theory/34064.py new file mode 100644 index 0000000..c6c9251 --- /dev/null +++ b/froglike6/graph_theory/34064.py @@ -0,0 +1,46 @@ +import sys +input = sys.stdin.readline + +N, M, K = map(int, input().split()) +grid = [[0]*M for _ in range(N)] +for _ in range(K): + x, y = map(int, input().split()) + grid[x-1][y-1] = 1 + +a1, b1 = map(int, input().split()) +a2, b2 = map(int, input().split()) +a3, b3 = map(int, input().split()) +a4, b4 = map(int, input().split()) + +a1, b1, a2, b2 = a1-1, b1-1, a2-1, b2-1 +a3, b3, a4, b4 = a3-1, b3-1, a4-1, b4-1 + +visited = [[False]*M for _ in range(N)] +dirs = [(1,0),(-1,0),(0,1),(0,-1)] +answer = 0 + +for i in range(N): + for j in range(M): + if grid[i][j] == 0 and not visited[i][j]: + stack = [(i, j)] + visited[i][j] = True + countA = 0 + countB = 0 + + while stack: + x, y = stack.pop() + if a1 <= x <= a2 and b1 <= y <= b2: + countA += 1 + if a3 <= x <= a4 and b3 <= y <= b4: + countB += 1 + + for dx, dy in dirs: + nx, ny = x + dx, y + dy + if 0 <= nx < N and 0 <= ny < M: + if grid[nx][ny] == 0 and not visited[nx][ny]: + visited[nx][ny] = True + stack.append((nx, ny)) + + answer += countA * countB + +print(answer) \ No newline at end of file