From a251e77e56d873678dd88a225df91e23eca0c2a8 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Fri, 22 Mar 2024 21:47:59 +0900 Subject: [PATCH] 2024-03-22 --- tgyuuAn/README.md | 1 + ...33\354\236\210\353\213\250\353\213\244.py" | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 "tgyuuAn/\354\210\230\355\225\231/\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.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 5d02ba78..1da8210b 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -44,4 +44,5 @@ | 40차시 | 2023.02.21 | DP | 입대 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142 | 41차시 | 2023.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148 | 42차시 | 2023.03.07 | DFS | 스도쿠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152 +| 47차시 | 2023.03.22 | 수학, 분할정복 | 너 봄에는 캡사이신이 맛있단다 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167 --- diff --git "a/tgyuuAn/\354\210\230\355\225\231/\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.py" "b/tgyuuAn/\354\210\230\355\225\231/\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.py" new file mode 100644 index 00000000..ac903fbb --- /dev/null +++ "b/tgyuuAn/\354\210\230\355\225\231/\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.py" @@ -0,0 +1,33 @@ +import sys + +DIV = 1_000_000_007 + +def input(): return sys.stdin.readline().rstrip() + +def power(n, over): + if over == 0: return 1 + elif over == 1: return n + elif over %2 == 0: + half = (power(n, over//2) % DIV) + return (half * half) % DIV + else: + half = (power(n, over//2) % DIV) + return (half * half * (n % DIV)) % DIV + +N = int(input()) +numbers = sorted(list(map(int,input().split()))) +DP = [-1 for _ in range(N)] +answer = 0 + +for start_idx in range(N): + start_num = numbers[start_idx] + end_num = numbers[N-start_idx-1] + + # 만약 캐싱이 되어있지 않을 경우 직접 계산 + if DP[N-start_idx-1] == -1: DP[N-start_idx-1] = power(2, N-start_idx-1) + + # 한번이라도 계산 했으면 바로 이용 + answer += ((end_num % DIV) * (DP[N-start_idx-1] % DIV)) % DIV + answer -= ((start_num % DIV) * (DP[N-start_idx-1] % DIV)) % DIV + +print(answer % DIV) \ No newline at end of file