-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from AlgoLeadMe/47-tgyuuAn
47-tgyuuAn
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tgyuuAn/μν/λ λ΄μλ μΊ‘μ¬μ΄μ μ΄ λ§μλ¨λ€.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |