| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(len(nums) - 2): if nums[i] < nums[i + 1] + nums[i + 2]: return nums[i] + nums[i + 1] + nums[i + 2] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| deepseek-r1 | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort() n = len(nums) prefix = [0] * n prefix[0] = nums[0] for i in range(1, n): prefix[i] = prefix[i-1] + nums[i] # Check from largest possible subset size down to 3 for m in range(n, 2, -1): if prefix[m-2] > nums[m-1]: return prefix[m-1] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort() total_sum = sum(nums) end = len(nums) - 1 while end + 1 >= 3: if total_sum > 2 * nums[end]: return total_sum total_sum -= nums[end] end -= 1 return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| gpt-4o-2024-08-06 | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: # Sort the numbers in descending order nums.sort(reverse=True) # Iterate over the sorted list and check for the largest valid polygon for i in range(len(nums) - 2): # Check if the current triplet can form a triangle if nums[i] < nums[i + 1] + nums[i + 2]: # If it can, return the perimeter return nums[i] + nums[i + 1] + nums[i + 2] # If no valid polygon can be formed, return -1 return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| DeepSeek-Coder-V2-Lite-Instruct | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(len(nums) - 2): if nums[i] < nums[i+1] + nums[i+2]: return nums[i] + nums[i+1] + nums[i+2] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(len(nums) - 2): if nums[i] < nums[i+1] + nums[i+2]: return nums[i] + nums[i+1] + nums[i+2] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(len(nums) - 2): if nums[i] < nums[i+1] + nums[i+2]: return nums[i] + nums[i+1] + nums[i+2] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| Qwen2-72B-Instruct | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(2, len(nums)): if nums[i] + nums[i-1] > nums[i-2]: return sum(nums[i-2:i+1]) return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| baichuan4 | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: # Sort the array in descending order nums.sort(reverse=True) # Check if the first three elements can form a triangle for i in range(len(nums) - 2): if nums[i] < nums[i + 1] + nums[i + 2]: # If they can, return the perimeter of the triangle return nums[i] + nums[i + 1] + nums[i + 2] # If no such triangle exists, return -1 return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| doubao | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(len(nums) - 2): if nums[i] < nums[i + 1] + nums[i + 2]: return nums[i] + nums[i + 1] + nums[i + 2] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort() total_sum = sum(nums) end = len(nums) - 1 while end + 1 >= 3: if total_sum > 2 * nums[end]: return total_sum total_sum -= nums[end] end -= 1 return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| kimi | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort(reverse=True) for i in range(len(nums) - 2): if nums[i] < nums[i + 1] + nums[i + 2]: return nums[i] + nums[i + 1] + nums[i + 2] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| minimax | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: # Sort the array in non-decreasing order nums.sort() # Iterate from the end of the array for i in range(len(nums) - 1, 1, -1): # Check if the current side can be the longest side of a polygon # by comparing it with the sum of the two smaller sides if nums[i] < nums[i - 1] + nums[i - 2]: # If it can, return the perimeter of the polygon return nums[i - 1] + nums[i - 2] + nums[i] # If no polygon can be formed, return -1 return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| wenxinyiyan | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: # Sort the array in ascending order nums.sort() n = len(nums) # Check for possible polygons from the largest sides for i in range(n-1, 1, -1): if nums[i-1] + nums[i-2] > nums[i]: # Found a valid polygon, return the perimeter return nums[i-1] + nums[i-2] + nums[i] # No valid polygon found return -1 ``` **Explanation**: 1. The first step is to sort the array `nums` in ascending order. This ensures that we can check for possible polygons starting from the largest sides. 2. We iterate over the sorted array in reverse order, starting from the second-to-last element (`n-1`) down to the second element (`1`). We skip the last element because we need at least three sides to form a polygon. 3. For each iteration, we check if the sum of the current element (`nums[i]`) and the two preceding elements (`nums[i-1]` and `nums[i-2]`) is greater than the current element. This condition ensures that the largest side is smaller than the sum of the other two sides, satisfying the polygon property. 4. If the condition is met, we have found a valid polygon. We return the perimeter by summing the three sides: `nums[i-1] + nums[i-2] + nums[i]`. 5. If we reach the end of the loop without finding a valid polygon, we return `-1` to indicate that it is not possible to create a polygon from the given array. Note: The solution assumes that the input array `nums` has at least three elements, as stated in the constraints (`3 <= n <= 10^5`). |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| zhipu | ```python from typing import List class Solution: def largestPerimeter(self, nums: List[int]) -> int: # Sort the list in non-decreasing order nums.sort() # Iterate from the end of the list to find the largest valid polygon for i in range(len(nums) - 3, -1, -1): # Check if the sum of the sides excluding the largest one is greater than the largest side if nums[i] + nums[i + 1] > nums[i + 2]: # If valid, return the perimeter of this polygon return nums[i] + nums[i + 1] + nums[i + 2] # If no valid polygon is found, return -1 return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |
| deepseek-v3 | ```python class Solution: def largestPerimeter(self, nums: List[int]) -> int: nums.sort() total = sum(nums) for i in range(len(nums) - 1, 1, -1): total -= nums[i] if total > nums[i]: return total + nums[i] return -1 ``` |
[{"input": "[5, 5, 5]", "output": "15", "testtype": "functional"}, {"input": "[1, 12, 1, 2, 5, 50, 3]", "output": "12", "testtype": "functional"}, {"input": "[5, 5, 50]", "output": "-1", "testtype": "functional"}] |