baekjoon 20260130
This commit is contained in:
parent
20ad5fa44b
commit
7bb31c1601
1
code_study/Baekjoon/python/10768.py
Normal file
1
code_study/Baekjoon/python/10768.py
Normal file
@ -0,0 +1 @@
|
||||
print((lambda m, d : "Before" if m == 1 else "After" if m > 2 else "Special" if d == 18 else "Before" if d < 18 else "After")(int(input()), int(input())))
|
||||
50
code_study/Baekjoon/ts/16724.ts
Normal file
50
code_study/Baekjoon/ts/16724.ts
Normal file
@ -0,0 +1,50 @@
|
||||
export {};
|
||||
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
||||
const [N, M]: number[] = input[0].split(" ").map(Number);
|
||||
let field: string[] = [];
|
||||
for(let i=1; i<=N; i++) field.push(input[i]);
|
||||
|
||||
let parents: number[] = Array.from({length: N*M}, (_, i) => i);
|
||||
let rank: number[] = new Array(N*M).fill(0);
|
||||
const areaNum = (col: number, row: number): number => { return M*row + col; }
|
||||
|
||||
const find = (x: number): number => {
|
||||
if(x !== parents[x]) return parents[x] = find(parents[x]);
|
||||
return parents[x];
|
||||
}
|
||||
|
||||
const union = (x: number, y: number) => {
|
||||
x = find(x);
|
||||
y = find(y);
|
||||
|
||||
if(x===y) return;
|
||||
|
||||
if(rank[x] < rank[y]) {
|
||||
const temp = x;
|
||||
x = y;
|
||||
y = temp;
|
||||
}
|
||||
|
||||
parents[y] = x;
|
||||
|
||||
if(rank[x] === rank[y]) rank[x]++;
|
||||
}
|
||||
|
||||
for(let x=0; x<M; x++) {
|
||||
for(let y=0; y<N; y++) {
|
||||
const arrow: string = field[y][x];
|
||||
const curArea: number = areaNum(x,y);
|
||||
let nxtArea: number = 0;
|
||||
|
||||
if(arrow === 'D') nxtArea = areaNum(x,y+1);
|
||||
else if(arrow === 'U') nxtArea = areaNum(x, y-1);
|
||||
else if(arrow === 'L') nxtArea = areaNum(x-1, y);
|
||||
else nxtArea = areaNum(x+1, y);
|
||||
|
||||
union(curArea, nxtArea);
|
||||
}
|
||||
}
|
||||
|
||||
let ans: number = 0;
|
||||
parents.forEach((v,i) => { if(v===i) ans += 1 });
|
||||
console.log(ans);
|
||||
Loading…
x
Reference in New Issue
Block a user