20250927 baekjoon
This commit is contained in:
parent
a6c97b96b6
commit
f0ead9ce24
35
code_study/Baekjoon/ts/1987.ts
Normal file
35
code_study/Baekjoon/ts/1987.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
export {};
|
||||||
|
|
||||||
|
const input: string[] = require("fs").readFileSync(0).toString().trim().split('\n');
|
||||||
|
const [R, C]: number[] = input[0].split(' ').map(Number);
|
||||||
|
|
||||||
|
let board: string[][] = [];
|
||||||
|
for(let i=1; i<=R; i++) {
|
||||||
|
board.push(input[i].split(''));
|
||||||
|
}
|
||||||
|
|
||||||
|
let alphabet: boolean[] = new Array(26).fill(false);
|
||||||
|
alphabet[board[0][0].charCodeAt(0) - 65] = true;
|
||||||
|
let maxStep: number = 1;
|
||||||
|
|
||||||
|
const dx: number[] = [1,-1,0,0];
|
||||||
|
const dy: number[] = [0,0,1,-1];
|
||||||
|
|
||||||
|
const dfs = ([cx, cy, cs]: number[]) => {
|
||||||
|
maxStep = Math.max(cs, maxStep);
|
||||||
|
|
||||||
|
for(let i=0; i<4; i++) {
|
||||||
|
const nx = cx + dx[i];
|
||||||
|
const ny = cy + dy[i];
|
||||||
|
|
||||||
|
if(0<=nx && nx<C && 0<=ny && ny<R && !alphabet[board[ny][nx].charCodeAt(0) - 65]) {
|
||||||
|
alphabet[board[ny][nx].charCodeAt(0) - 65] = true;
|
||||||
|
dfs([nx,ny,cs+1]);
|
||||||
|
alphabet[board[ny][nx].charCodeAt(0) - 65] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dfs([0,0,1]);
|
||||||
|
|
||||||
|
console.log(maxStep);
|
||||||
Loading…
x
Reference in New Issue
Block a user