From 3ff16c6bff7cf79f417eda2baffb44c2684888bb Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sun, 3 Aug 2025 10:52:01 +0900 Subject: [PATCH] 20250803 baekjoon --- code_study/Baekjoon/python/2667.py | 37 +++++++++++++++++++++++++++++ code_study/Baekjoon/ts/2178.ts | 38 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 code_study/Baekjoon/python/2667.py create mode 100644 code_study/Baekjoon/ts/2178.ts diff --git a/code_study/Baekjoon/python/2667.py b/code_study/Baekjoon/python/2667.py new file mode 100644 index 0000000..f7f412c --- /dev/null +++ b/code_study/Baekjoon/python/2667.py @@ -0,0 +1,37 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +def BFS(filedMap, visited, x, y, N): + queue = deque([(x,y)]) + visited[y][x] = True + cnt = 1 + + dx = [1,-1,0,0] + dy = [0,0,1,-1] + + while len(queue): + cx, cy = queue.popleft() + for i in range(4): + nx, ny = cx + dx[i], cy + dy[i] + if 0<=nx 0 : + cntEstate.append(BFS(filedMap, visited, j, i, N)) + +result = str(len(cntEstate)) + '\n' + '\n'.join(map(str, sorted(cntEstate))) +print(result) \ No newline at end of file diff --git a/code_study/Baekjoon/ts/2178.ts b/code_study/Baekjoon/ts/2178.ts new file mode 100644 index 0000000..cd88fe9 --- /dev/null +++ b/code_study/Baekjoon/ts/2178.ts @@ -0,0 +1,38 @@ +export {}; + +const input: string[] = require("fs").readFileSync(0,"utf8").toString().trim().split('\n'); +const [N, M]:number[] = input[0].split(' ').map(Number); +let Meero:number[][] = Array.from({length: N+1}, () => new Array(M+1).fill(0)); +let visited:number[][] = Array.from({length: N+1}, () => new Array(M+1).fill(0)); +let queueX: number[] = [] +let queueY: number[] = [] +const dx:number[] = [1,-1,0,0]; +const dy:number[] = [0,0,1,-1]; + +Meero.forEach((_,i,arr) => { + if(i!==0) { + arr[i] = ('0'+input[i]).split("").map(Number); + } +}); + +queueX.push(1); +queueY.push(1); +visited[1][1] = 1; + +while(queueX.length!==0){ + const [cx, cy]:number[] = [queueX.shift()!, queueY.shift()!]; + if(cx===M && cy===N){ + console.log(visited[N][M]); + break; + } + + for(let i=0; i<4; i++){ + const[nx, ny] = [cx + dx[i], cy + dy[i]]; + const goPossible: boolean = 0