문제 · 알고리즘 보통 Python ·
Partition into equal sums
Return True if the list of positive integers can be split into two groups with equal sums (every number goes into exactly one group; a group may be empty). Up to 200 numbers, each at most 500.
함수 시그니처
def can_partition(nums: list[int]) -> bool:예제
can_partition([1, 5, 11, 5]) # -> True
can_partition([1, 2, 3, 5]) # -> False제한 시간이 적용되는 7 개의 비공개 테스트와 2 개의 대규모 입력 테스트가 추가로 진행되며, 입력값은 공개되지 않습니다. 문제는 모델에 영어로 주어집니다.
1위MoonshotAI Kimi K2.7 Code해결 · 테스트 11/11 통과응답 소요 2.5 초 · 실행 시간 7 ms · $0.0013 ✓ can_partition([1, 5, 11, 5])기댓값 True <1 ms ✓ can_partition([1, 2, 3, 5])기댓값 False <1 ms ✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ 1 ms✓ <1 ms✓ <1 ms⏱ <1 ms⏱ <1 ms코드
def can_partition(nums: list[int]) -> bool: total = sum(nums) if total & 1: return False target = total >> 1 possible = 1 for num in nums: possible |= possible << num if possible >> target & 1: return True return (possible >> target) & 1 == 11위Anthropic Claude Haiku 5.5해결 · 테스트 11/11 통과응답 소요 1.1 초 · 실행 시간 16 ms · $0.0001 ✓ can_partition([1, 5, 11, 5])기댓값 True <1 ms ✓ can_partition([1, 2, 3, 5])기댓값 False 9 ms ✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms⏱ <1 ms⏱ <1 ms코드
def can_partition(nums: list[int]) -> bool: total = sum(nums) if total % 2: return False target = total // 2 if target == 0: return True mask = 1 for x in nums: mask |= mask << x if (mask >> target) & 1: return True return bool((mask >> target) & 1)1위Qwen3 Coder Next해결 · 테스트 11/11 통과응답 소요 2.3 초 · 실행 시간 19 ms · $0.0002 ✓ can_partition([1, 5, 11, 5])기댓값 True 1 ms ✓ can_partition([1, 2, 3, 5])기댓값 False <1 ms ✓ <1 ms✓ 1 ms✓ <1 ms✓ <1 ms✓ 2 ms✓ <1 ms✓ 6 ms⏱ 1 ms⏱ 3 ms코드
def can_partition(nums: list[int]) -> bool: total = sum(nums) # If total sum is odd, impossible to split into two equal parts if total % 2 != 0: return False target = total // 2 # dp[i] represents whether sum i is achievable dp = [False] * (target + 1) dp[0] = True # Sum 0 is always achievable (empty subset) for num in nums: # Traverse from right to left to avoid using the same number twice for i in range(target, num - 1, -1): if dp[i - num]: dp[i] = True return dp[target]4위SpaceXAI Grok 4.7미해결 · 테스트 10/11 통과응답 소요 27 초 · 실행 시간 7 ms · $0.01 ✓ can_partition([1, 5, 11, 5])기댓값 True 1 ms ✓ can_partition([1, 2, 3, 5])기댓값 False <1 ms ✗ 오답✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms✓ <1 ms⏱ <1 ms⏱ <1 ms코드
def can_partition(nums: list[int]) -> bool: total = sum(nums) if total & 1: return False target = total >> 1 reachable = 1 mask = (1 << (target + 1)) - 1 for x in nums: reachable |= (reachable << x) & mask if reachable & (1 << target): return True return False2차 시도
해결 · 테스트 11/11 통과응답 소요 110 초 · $0.04모델에게 실패한 테스트 수, 실패한 예시의 기댓값 및 반환값, 그리고 비공개 테스트의 입력값을 제외한 실패 원인만 제공되었습니다. 순위나 레이팅에는 반영되지 않습니다.
✓ can_partition([1, 5, 11, 5])기댓값 True <1 ms ✓ can_partition([1, 2, 3, 5])기댓값 False <1 ms ✓ <1 ms✓ 2 ms✓ <1 ms✓ 1 ms✓ <1 ms✓ <1 ms✓ <1 ms⏱ <1 ms⏱ <1 ms코드
def can_partition(nums: list[int]) -> bool: total = sum(nums) if total & 1: return False target = total >> 1 reachable = 1 if (reachable >> target) & 1: return True mask = (1 << (target + 1)) - 1 for x in nums: reachable |= (reachable << x) & mask if (reachable >> target) & 1: return True return False
토큰 비용: $0.06 · 진행 방식 및 점수 산정 안내 →