From a2e7ddc742f75fa2f7505c9667e3dda7e70fd174 Mon Sep 17 00:00:00 2001 From: HeeEul Shin <83682424+ShinHeeEul@users.noreply.github.com> Date: Thu, 17 Apr 2025 11:01:57 +0900 Subject: [PATCH] =?UTF-8?q?[20250417]=20BOJ=20/=20G2=20/=20=EB=84=88=20?= =?UTF-8?q?=EB=B4=84=EC=97=90=EB=8A=94=20=EC=BA=A1=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EC=8B=A0=EC=9D=B4=20=EB=A7=9B=EC=9E=88=EB=8B=A8=EB=8B=A4=20=20?= =?UTF-8?q?/=20=EC=8B=A0=ED=9D=AC=EC=9D=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...33\354\236\210\353\213\250\353\213\244.md" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "ShinHeeEul/202504/17 BOJ G2 \353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.md" diff --git "a/ShinHeeEul/202504/17 BOJ G2 \353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.md" "b/ShinHeeEul/202504/17 BOJ G2 \353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.md" new file mode 100644 index 00000000..67f4e104 --- /dev/null +++ "b/ShinHeeEul/202504/17 BOJ G2 \353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.md" @@ -0,0 +1,87 @@ +```java +import java.util.*; +import java.io.*; + +class Main { + + static int MOD = 1_000_000_007; + + static StringBuilder sb = new StringBuilder(); + static String s; + static long[] arr; + static long[] max; + static long[] min; + static long ans = 0; + static int N; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = read(); + + // 슬라이딩 윈도우 처럼 + arr = new long[N]; + + for(int i = 0; i < N; i++) { + arr[i] = read(); + } + + // 정렬 하고? + Arrays.sort(arr); + + long[] pow2 = new long[N]; + pow2[0] = 1; + for (int i = 1; i < N; i++) { + pow2[i] = (pow2[i-1] * 2) % MOD; + } + + + + for(int i = arr.length - 1; i >= 0; i--) { + ans = (ans + arr[i] * ((pow(2, i) - pow(2, N - i - 1) + MOD) % MOD) % MOD) % MOD; + } + + + System.out.println(ans); + } + + + public static long pow(long n, long r) { + + n %= MOD; + long result = 1L; + while(r > 0) { + if((r & 1) == 1) { + result = (result * n) % MOD; + } + n = (n * n) % MOD; + r >>= 1; + } + + return result % MOD; + } + + private static int read() throws Exception { + int c; + int n = 0; + boolean negative = false; + + while ((c = System.in.read()) <= 32) { + if (c == -1) return -1; + } + + if (c == '-') { + negative = true; + c = System.in.read(); + } + + do { + n = n * 10 + (c - '0'); + c = System.in.read(); + } while (c > 32); + + return negative ? -n : n; + } + + +} +```