From 25e03503a2540cb0852c4ccefc591d58d2b9aaab Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 21 Sep 2025 20:07:34 +0900 Subject: [PATCH] =?UTF-8?q?[20250921]=20BOJ=20/=20G4=20/=20=EC=88=98?= =?UTF-8?q?=EB=93=A4=EC=9D=98=20=ED=95=A9=204=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\223\244\354\235\230 \355\225\251 4.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "lkhyun/202509/21 BOJ G4 \354\210\230\353\223\244\354\235\230 \355\225\251 4.md" diff --git "a/lkhyun/202509/21 BOJ G4 \354\210\230\353\223\244\354\235\230 \355\225\251 4.md" "b/lkhyun/202509/21 BOJ G4 \354\210\230\353\223\244\354\235\230 \355\225\251 4.md" new file mode 100644 index 00000000..2845a2a3 --- /dev/null +++ "b/lkhyun/202509/21 BOJ G4 \354\210\230\353\223\244\354\235\230 \355\225\251 4.md" @@ -0,0 +1,38 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,K; + static long[] A; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + A = new long[N+1]; + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + A[i] = A[i-1] + Integer.parseInt(st.nextToken()); + } + + Map SumCount = new HashMap<>(); + long count = 0; + + SumCount.put(0L, 1); + + for (int j = 1; j <= N; j++) { + long target = A[j] - K; + count += SumCount.getOrDefault(target, 0); + + SumCount.put(A[j], SumCount.getOrDefault(A[j], 0) + 1); + } + bw.write(count + "\n"); + bw.close(); + } +} +```