ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 8318 |
문제명 | Blindfold Nim |
레벨 | 플래티넘 3 |
분류 |
그리디 |
시간복잡도 | O(nlogm) |
인풋사이즈 | n<=1,000,000, m<=1,000,000 |
사용한 언어 | Python 3.11 |
제출기록 | 55292KB / 884ms |
최고기록 | 884ms |
해결날짜 | 2023/12/13 |
"""Solution code for "BOJ 8318. Blindfold Nim".
- Problem link: https://www.acmicpc.net/problem/8318
- Solution link: http://www.teferi.net/ps/problems/boj/8318
Tags: [game theory]
"""
import heapq
def main():
n = int(input())
a = [int(x) for x in input().split()]
answer = 0
p = 1
heap = [-a_i for a_i in a]
heapq.heapify(heap)
while heap:
player_stack = -heapq.heappop(heap)
p *= player_stack / (player_stack + 1)
if player_stack > 1:
heapq.heappush(heap, -(player_stack - 1))
if not heap:
answer += p
break
opponent_stack = -heapq.heappop(heap)
answer += p / (opponent_stack + 1)
p *= opponent_stack / (opponent_stack + 1)
if opponent_stack > 1:
heapq.heappush(heap, -(opponent_stack - 1))
print(answer)
if __name__ == '__main__':
main()