20251114 baekjoon
This commit is contained in:
parent
a8e072c3b2
commit
45a1658511
25
code_study/Baekjoon/ts/10942.ts
Normal file
25
code_study/Baekjoon/ts/10942.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
export {};
|
||||||
|
const input = require("fs").readFileSync(0).toString().trim().split("\n");
|
||||||
|
const [N, M]: number[] = [input[0], input[2]].map(Number);
|
||||||
|
const nums: number[] = input[1].split(" ").map(Number);
|
||||||
|
|
||||||
|
const ans: number[][] = [];
|
||||||
|
for(let i=0; i<M; i++) ans.push(input[3+i].split(" ").map(Number));
|
||||||
|
|
||||||
|
let dp: number[][] = Array.from({length: N}, () => new Array(N).fill((0)));
|
||||||
|
|
||||||
|
for(let i=0; i<N; i++) {
|
||||||
|
dp[i][i] = 1;
|
||||||
|
if(i < N-1 && nums[i]===nums[i+1]) dp[i][i+1] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let len=3; len<=N; len++) {
|
||||||
|
for(let s=0; s<=N-len; s++) {
|
||||||
|
const e = s+len-1;
|
||||||
|
if(nums[s] === nums[e] && dp[s+1][e-1]===1) dp[s][e] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: number[] = [];
|
||||||
|
for(let [s,e] of ans) result.push(dp[s-1][e-1]);
|
||||||
|
console.log(result.join('\n'));
|
||||||
Loading…
x
Reference in New Issue
Block a user