From de707b91aeb9f1e36f8f35e47197fb40aad90521 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:38:39 +0900 Subject: [PATCH] =?UTF-8?q?[20250616]=20BOJ=20/=20G2=20/=20=ED=95=A9?= =?UTF-8?q?=EC=9D=B4=200=EC=9D=B8=20=EB=84=A4=20=EC=A0=95=EC=88=98=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \353\204\244 \354\240\225\354\210\230.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "lkhyun/202506/16 BOJ G2 \355\225\251\354\235\264 0\354\235\270 \353\204\244 \354\240\225\354\210\230.md" diff --git "a/lkhyun/202506/16 BOJ G2 \355\225\251\354\235\264 0\354\235\270 \353\204\244 \354\240\225\354\210\230.md" "b/lkhyun/202506/16 BOJ G2 \355\225\251\354\235\264 0\354\235\270 \353\204\244 \354\240\225\354\210\230.md" new file mode 100644 index 00000000..6c6e067e --- /dev/null +++ "b/lkhyun/202506/16 BOJ G2 \355\225\251\354\235\264 0\354\235\270 \353\204\244 \354\240\225\354\210\230.md" @@ -0,0 +1,69 @@ +```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; + static int[] A; + static int[] B; + static int[] C; + static int[] D; + static int[] AB; + static int[] CD; + static long answer = 0; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + A = new int[N]; + B = new int[N]; + C = new int[N]; + D = new int[N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + A[i] = Integer.parseInt(st.nextToken()); + B[i] = Integer.parseInt(st.nextToken()); + C[i] = Integer.parseInt(st.nextToken()); + D[i] = Integer.parseInt(st.nextToken()); + } + + AB = new int[N*N]; + CD = new int[N*N]; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + AB[i*N+j] = A[i] + B[j]; + CD[i*N+j] = C[i] + D[j]; + } + } + Arrays.sort(AB); + Arrays.sort(CD); + + int left = 0, right = N*N-1; + while (left < N*N && right >= 0) { + if(AB[left] + CD[right] == 0){ + int leftCnt = 1; + while(left + 1 < N*N && AB[left+1] == AB[left]){ + left++; + leftCnt++; + } + int rightCnt = 1; + while(right - 1 >= 0 && CD[right-1] == CD[right]){ + right--; + rightCnt++; + } + answer += (long)leftCnt * rightCnt; + left++; + right--; + }else if(AB[left] + CD[right] < 0){ + left++; + }else{ + right--; + } + } + bw.write(answer + "\n"); + bw.close(); + } +} +```