baekjoon 20251211

This commit is contained in:
songyc macbook 2025-12-11 22:44:34 +09:00
parent 289d125a19
commit 7311a379dc
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,4 @@
import sys
input = sys.stdin.readline
for i in range(1, int(input())+1) :
print(f"Case {i}:",sum(map(int, input().split())))

View File

@ -0,0 +1,35 @@
export {};
const [s1, s2]: string[] = require("fs").readFileSync(0).toString().trim().split("\n");
const [l1, l2]: number[] = [s1.length, s2.length];
let dp: number[][] = Array.from({length: l1+1}, () => new Array(l2+1).fill(0));
for(let i=1; i<=l1; i++) {
let c1: string = s1[i-1];
for(let j=1; j<=l2; j++) {
let c2: string = s2[j-1];
if(c1 === c2) dp[i][j] = dp[i-1][j-1] + 1;
else dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
}
}
console.log(dp[l1][l2]);
if(dp[l1][l2] !== 0) {
let [p1, p2]: number[] = [l1, l2];
let result: string[] = [];
while(!(p1===0 || p2===0)) {
const [c1, c2]: string[] = [s1[p1-1], s2[p2-1]];
if(dp[p1][p2] === dp[p1][p2-1]) p2--;
else if(dp[p1][p2] === dp[p1-1][p2]) p1--;
else {
result.push(c1);
p1--; p2--;
}
}
console.log(result.reverse().join(""));
}