baekjoon 20260211
This commit is contained in:
parent
6b8a5a1308
commit
1c0306e017
10
code_study/Baekjoon/python/2010.py
Normal file
10
code_study/Baekjoon/python/2010.py
Normal file
@ -0,0 +1,10 @@
|
||||
import sys
|
||||
input = sys.stdin.readline
|
||||
ans = 0
|
||||
for i in range(int(input())) :
|
||||
if i == 0 :
|
||||
ans += int(input())
|
||||
else :
|
||||
ans = ans - 1 + int(input())
|
||||
|
||||
print(ans)
|
||||
60
code_study/Baekjoon/ts/2143.ts
Normal file
60
code_study/Baekjoon/ts/2143.ts
Normal file
@ -0,0 +1,60 @@
|
||||
export {};
|
||||
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
||||
|
||||
const T: number = Number(input[0]);
|
||||
const [n, m]: number[] = [Number(input[1]), Number(input[3])];
|
||||
const A: number[] = input[2].split(" ").map(Number);
|
||||
const B: number[] = input[4].split(" ").map(Number);
|
||||
|
||||
let sumA: number[] = [];
|
||||
for(let i=0; i<n; i++) {
|
||||
let temp: number = 0
|
||||
for(let j=i; j<n; j++) {
|
||||
temp += A[j];
|
||||
sumA.push(temp);
|
||||
}
|
||||
}
|
||||
|
||||
let sumB: number[] = [];
|
||||
for(let i=0; i<m; i++) {
|
||||
let temp: number = 0
|
||||
for(let j=i; j<m; j++) {
|
||||
temp += B[j];
|
||||
sumB.push(temp);
|
||||
}
|
||||
}
|
||||
|
||||
sumA.sort((a,b) => a - b);
|
||||
sumB.sort((a,b) => b - a);
|
||||
const [N, M]: number[] = [sumA.length, sumB.length];
|
||||
|
||||
let [ptA, ptB]: number[] = [0, 0];
|
||||
let ans: number = 0;
|
||||
|
||||
while (ptA < N && ptB < M) {
|
||||
const curr: number = sumA[ptA] + sumB[ptB];
|
||||
|
||||
if(curr !== T ) {
|
||||
if(T > curr) ptA++;
|
||||
else if(T < curr) ptB++;
|
||||
continue;
|
||||
}
|
||||
|
||||
let cntA: number = 0;
|
||||
let valA: number = sumA[ptA];
|
||||
while(ptA < N && sumA[ptA] === valA) {
|
||||
cntA++;
|
||||
ptA++;
|
||||
}
|
||||
|
||||
let cntB: number = 0;
|
||||
let valB: number = sumB[ptB];
|
||||
while(ptB < M && sumB[ptB] === valB) {
|
||||
cntB++;
|
||||
ptB++;
|
||||
}
|
||||
|
||||
ans += cntA*cntB;
|
||||
}
|
||||
|
||||
console.log(ans);
|
||||
Loading…
x
Reference in New Issue
Block a user