Skip to content

Commit

Permalink
Merge pull request #167 from AlgoLeadMe/47-tgyuuAn
Browse files Browse the repository at this point in the history
47-tgyuuAn
  • Loading branch information
tgyuuAn authored Apr 22, 2024
2 parents 92f8388 + b04c16c commit 124514a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@
| 44μ°¨μ‹œ | 2023.03.13 | 트라이 | <a href="https://www.acmicpc.net/problem/14725">개미꡴</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
| 45μ°¨μ‹œ | 2023.03.16 | 트라이 | <a href="https://www.acmicpc.net/problem/31413">트라이</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
| 46μ°¨μ‹œ | 2023.03.20 | 트라이 | <a href="https://www.acmicpc.net/problem/27652">AB</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/165
| 47μ°¨μ‹œ | 2023.03.22 | μˆ˜ν•™, 뢄할정볡 | <a href="https://www.acmicpc.net/problem/15824">λ„ˆ λ΄„μ—λŠ” 캑사이신이 λ§›μžˆλ‹¨λ‹€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167
---
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 124514a

Please sign in to comment.