Skip to content

Commit

Permalink
2024-03-22
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Mar 22, 2024
1 parent 0c41f9e commit a251e77
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 @@ -44,4 +44,5 @@
| 40μ°¨μ‹œ | 2023.02.21 | DP | <a href="https://www.acmicpc.net/problem/31413">μž…λŒ€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
| 41μ°¨μ‹œ | 2023.03.04 | DP | <a href="https://www.acmicpc.net/problem/2240">μžλ‘λ‚˜λ¬΄</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
| 42μ°¨μ‹œ | 2023.03.07 | DFS | <a href="https://www.acmicpc.net/problem/2239">μŠ€λ„μΏ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152
| 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 a251e77

Please sign in to comment.