| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: m = len(pattern) count = 0 for i in range(len(nums) - m): match = True for k in range(m): if pattern[k] == 1 and nums[i + k + 1] <= nums[i + k]: match = False break if pattern[k] == 0 and nums[i + k + 1] != nums[i + k]: match = False break if pattern[k] == -1 and nums[i + k + 1] >= nums[i + k]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| deepseek-r1 | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: # Generate the differences array diff = [] for j in range(len(nums) - 1): a, b = nums[j], nums[j+1] if b > a: diff.append(1) elif b == a: diff.append(0) else: diff.append(-1) m = len(pattern) if m > len(diff): return 0 count = 0 # Check each possible starting index in the differences array for i in range(len(diff) - m + 1): # Extract the subarray of length m current = diff[i:i+m] if current == pattern: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: count = 0 n = len(nums) m = len(pattern) for i in range(n - m): match = True for k in range(m): if pattern[k] == 1: if nums[i + k + 1] <= nums[i + k]: match = False break elif pattern[k] == 0: if nums[i + k + 1] != nums[i + k]: match = False break elif pattern[k] == -1: if nums[i + k + 1] >= nums[i + k]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| gpt-4o-2024-08-06 | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n = len(nums) m = len(pattern) count = 0 for i in range(n - m): match = True for k in range(m): if pattern[k] == 1 and not (nums[i + k + 1] > nums[i + k]): match = False break elif pattern[k] == 0 and not (nums[i + k + 1] == nums[i + k]): match = False break elif pattern[k] == -1 and not (nums[i + k + 1] < nums[i + k]): match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| DeepSeek-Coder-V2-Lite-Instruct | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n = len(nums) m = len(pattern) count = 0 for i in range(n - m): match = True for j in range(m): if (pattern[j] == 1 and nums[i + j + 1] <= nums[i + j]) or \ (pattern[j] == 0 and nums[i + j + 1] != nums[i + j]) or \ (pattern[j] == -1 and nums[i + j + 1] >= nums[i + j]): match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n, m = len(nums), len(pattern) count = 0 for i in range(n - m): match = True for j in range(m): if (pattern[j] == 1 and nums[i + j + 1] <= nums[i + j]) or \ (pattern[j] == 0 and nums[i + j + 1] != nums[i + j]) or \ (pattern[j] == -1 and nums[i + j + 1] >= nums[i + j]): match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python class Solution: def numSub(self, nums: List[int], pattern: List[int]) -> int: n, m = len(nums), len(pattern) res = 0 for i in range(n - m + 1): match = True for j in range(m): if pattern[j] == 1 and nums[i + j] >= nums[i + j + 1]: match = False break elif pattern[j] == 0 and nums[i + j] != nums[i + j + 1]: match = False break elif pattern[j] == -1 and nums[i + j] <= nums[i + j + 1]: match = False break if match: res += 1 return res ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| Qwen2-72B-Instruct | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n, m = len(nums), len(pattern) count = 0 for i in range(n-m): match = True for j in range(m): if pattern[j] == 1 and not nums[i+j+1] > nums[i+j]: match = False break elif pattern[j] == 0 and not nums[i+j+1] == nums[i+j]: match = False break elif pattern[j] == -1 and not nums[i+j+1] < nums[i+j]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| baichuan4 | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: m = len(pattern) count = 0 for i in range(len(nums) - m): match = True for j in range(m): if pattern[j] == 1 and nums[i + j] >= nums[i + j + 1]: match = False break elif pattern[j] == 0 and nums[i + j] != nums[i + j + 1]: match = False break elif pattern[j] == -1 and nums[i + j] <= nums[i + j + 1]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| doubao | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n = len(nums) m = len(pattern) count = 0 for i in range(n - m): match = True for j in range(m): if pattern[j] == 1 and nums[i + j + 1] <= nums[i + j]: match = False break if pattern[j] == -1 and nums[i + j + 1] >= nums[i + j]: match = False break if pattern[j] == 0 and nums[i + j + 1]!= nums[i + j]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: count = 0 n = len(nums) m = len(pattern) for i in range(n - m): match = True for k in range(m): if pattern[k] == 1: if nums[i + k + 1] <= nums[i + k]: match = False break elif pattern[k] == 0: if nums[i + k + 1] != nums[i + k]: match = False break elif pattern[k] == -1: if nums[i + k + 1] >= nums[i + k]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| kimi | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n, m = len(nums), len(pattern) res = 0 for i in range(n - m): match = True for j in range(m): if pattern[j] == 1 and nums[i + j + 1] <= nums[i + j]: match = False elif pattern[j] == 0 and nums[i + j + 1] != nums[i + j]: match = False elif pattern[j] == -1 and nums[i + j + 1] >= nums[i + j]: match = False if match: res += 1 return res ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| minimax | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n = len(nums) m = len(pattern) count = 0 # Iterate over the array to find all possible subarrays of size m+1 for i in range(n - m): # Check if the current subarray matches the pattern if all( (nums[i + k + 1] > nums[i + k] if pattern[k] == 1 else nums[i + k + 1] == nums[i + k] if pattern[k] == 0 else nums[i + k + 1] < nums[i + k]) for k in range(m) ): count += 1 return count # Example usage: # sol = Solution() # print(sol.countMatchingSubarrays([1,2,3,4,5,6], [1,1])) # Output: 4 # print(sol.countMatchingSubarrays([1,4,4,1,3,5,5,3], [1,0,-1])) # Output: 2 ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| wenxinyiyan | ```python from typing import List class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n = len(nums) m = len(pattern) count = 0 for i in range(n - m): match = True for j in range(m): if pattern[j] == 1 and nums[i + j + 1] <= nums[i + j]: match = False break elif pattern[j] == 0 and nums[i + j + 1] != nums[i + j]: match = False break elif pattern[j] == -1 and nums[i + j + 1] >= nums[i + j]: match = False break if match: count += 1 return count ``` This solution iterates over the `nums` array using a sliding window approach. For each starting index `i` from 0 to `n - m - 1`, it checks if the subarray `nums[i:i+m+1]` matches the given `pattern`. The inner loop iterates over the `pattern` array and compares the corresponding elements in the `nums` subarray according to the conditions specified in the problem statement. If any condition is violated, the `match` flag is set to `False` and the inner loop is exited using `break`. If the `match` flag remains `True` after the inner loop, it means the subarray matches the pattern, and the `count` variable is incremented. Finally, the function returns the total count of matching subarrays. |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| zhipu | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: count = 0 n = len(nums) m = len(pattern) for i in range(n - m - 1): match = True for k in range(m): if pattern[k] == 1 and nums[i + k + 1] <= nums[i + k]: match = False break elif pattern[k] == 0 and nums[i + k + 1] != nums[i + k]: match = False break elif pattern[k] == -1 and nums[i + k + 1] >= nums[i + k]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |
| deepseek-v3 | ```python class Solution: def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int: n = len(nums) m = len(pattern) count = 0 for i in range(n - m): match = True for k in range(m): if pattern[k] == 1: if nums[i + k + 1] <= nums[i + k]: match = False break elif pattern[k] == 0: if nums[i + k + 1] != nums[i + k]: match = False break elif pattern[k] == -1: if nums[i + k + 1] >= nums[i + k]: match = False break if match: count += 1 return count ``` |
[{"input": "[1, 2, 3, 4, 5, 6]\n[1, 1]", "output": "4", "testtype": "functional"}, {"input": "[1, 4, 4, 1, 3, 5, 5, 3]\n[1, 0, -1]", "output": "2", "testtype": "functional"}] |