baekjoon 20260109
This commit is contained in:
parent
fafa00de92
commit
95e79a15e9
58
code_study/Baekjoon/ts/7453.ts
Normal file
58
code_study/Baekjoon/ts/7453.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
export {};
|
||||||
|
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
||||||
|
|
||||||
|
const n: number = Number(input[0]);
|
||||||
|
let A = new Int32Array(n);
|
||||||
|
let B = new Int32Array(n);
|
||||||
|
let C = new Int32Array(n);
|
||||||
|
let D = new Int32Array(n);
|
||||||
|
|
||||||
|
for(let i=0; i<n; i++) {
|
||||||
|
let [a, b, c, d]: number[] = input[i+1].split(" ").map(Number);
|
||||||
|
A[i] = a, B[i] = b, C[i] = c, D[i] = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
const LIM: number = n*n;
|
||||||
|
let AB = new Int32Array(LIM);
|
||||||
|
let CD = new Int32Array(LIM);
|
||||||
|
|
||||||
|
let idx: number = 0
|
||||||
|
for(let i=0; i<n; i++) {
|
||||||
|
for(let j=0; j<n; j++) {
|
||||||
|
AB[idx] = A[i] + B[j];
|
||||||
|
CD[idx] = C[i] + D[j];
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AB.sort();
|
||||||
|
CD.sort().reverse();
|
||||||
|
|
||||||
|
let [idxAB, idxCD]: number[] = [0, 0];
|
||||||
|
let ans: bigint = BigInt(0);
|
||||||
|
|
||||||
|
while(idxAB < LIM && idxCD < LIM) {
|
||||||
|
const [numAB, numCD]: number[] = [AB[idxAB], CD[idxCD]];
|
||||||
|
|
||||||
|
const ABCD: number = numAB + numCD;
|
||||||
|
|
||||||
|
if(ABCD === 0) {
|
||||||
|
let [sameAB, sameCD]: number[] = [0,0];
|
||||||
|
|
||||||
|
while(idxAB < LIM && numAB === AB[idxAB]) {
|
||||||
|
sameAB++;
|
||||||
|
idxAB++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(idxCD < LIM && numCD === CD[idxCD]) {
|
||||||
|
sameCD++;
|
||||||
|
idxCD++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ans += BigInt(sameAB)*BigInt(sameCD);
|
||||||
|
}
|
||||||
|
else if(ABCD < 0) idxAB++;
|
||||||
|
else idxCD++;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(ans.toString());
|
||||||
Loading…
x
Reference in New Issue
Block a user