diff --git "a/zinnnn37/202601/29 BOJ G2 \355\225\251\354\235\264 0\354\235\270 \353\204\244 \354\240\225\354\210\230.md" "b/zinnnn37/202601/29 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..d59ab538 --- /dev/null +++ "b/zinnnn37/202601/29 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,84 @@ +```java +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BJ_7453_합이_0인_네_정수 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N; + private static long cnt; + private static int[] A, B, C, D; + private static int[] AB, CD; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + cnt = 0; + + 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]; + } + + private static void sol() throws IOException { + int idx = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + AB[idx] = A[i] + B[j]; + CD[idx++] = C[i] + D[j]; + } + } + Arrays.sort(AB); + Arrays.sort(CD); + + int left = 0; + int right = N * N - 1; + while (left < N * N && right >= 0) { + int sum = AB[left] + CD[right]; + + if (sum == 0) { + int lVal = AB[left]; + int rVal = CD[right]; + + long lCnt = 1; + long rCnt = 1; + while (++left < N * N && AB[left] == lVal) { + lCnt++; + } + while (--right >= 0 && CD[right] == rVal) { + rCnt++; + } + cnt += (long) lCnt * rCnt; + } else if (sum < 0) { + left++; + } else { + right--; + } + } + bw.write(cnt + ""); + bw.flush(); + bw.close(); + br.close(); + } + +} +```