| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ```python class Solution: def maximumLength(self, s: str) -> int: from collections import defaultdict # Dictionary to store the count of each special substring count = defaultdict(int) # Iterate through the string to count special substrings for i in range(len(s)): for j in range(i + 1, len(s) + 1): substring = s[i:j] if len(set(substring)) == 1: # Check if the substring is special count[substring] += 1 # Find the longest special substring that occurs at least thrice max_length = -1 for substring, freq in count.items(): if freq >= 3: max_length = max(max_length, len(substring)) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| deepseek-r1 | ```python from collections import defaultdict class Solution: def maximumLength(self, s: str) -> int: run_dict = defaultdict(list) current_char = s[0] current_length = 1 for char in s[1:]: if char == current_char: current_length += 1 else: run_dict[current_char].append(current_length) current_char = char current_length = 1 run_dict[current_char].append(current_length) freq = defaultdict(int) for c in run_dict: for run_len in run_dict[c]: for k in range(1, run_len + 1): contribution = run_len - k + 1 freq[(c, k)] += contribution max_len = -1 for (c, k) in freq: if freq[(c, k)] >= 3 and k > max_len: max_len = k return max_len if max_len != -1 else -1 ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def maximumLength(self, s: str) -> int: n = len(s) for L in range(n, 0, -1): for c in 'abcdefghijklmnopqrstuvwxyz': count = 0 substr = c * L for i in range(n - L + 1): if s[i] == c and s[i:i+L] == substr: count += 1 if count >= 3: return L return -1 ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| gpt-4o-2024-08-06 | ```python class Solution: def maximumLength(self, s: str) -> int: from collections import defaultdict # Dictionary to store the maximum length of special substrings for each character max_length = defaultdict(int) # Iterate over the string to find all special substrings n = len(s) i = 0 while i < n: char = s[i] j = i # Find the length of the special substring starting at i while j < n and s[j] == char: j += 1 length = j - i # Update the maximum length for this character max_length[char] = max(max_length[char], length) i = j # Check for each character if there is a special substring that occurs at least thrice result = -1 for char in max_length: # Count occurrences of this character in the string count = s.count(char) # If the character occurs at least thrice, consider its maximum special substring length if count >= 3: result = max(result, max_length[char]) return result ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| DeepSeek-Coder-V2-Lite-Instruct | ```python class Solution: def maximumLength(self, s: str) -> int: n = len(s) max_length = -1 # Check all possible lengths of special substrings for length in range(1, n + 1): count = {} # Count occurrences of each substring of the current length for i in range(n - length + 1): substring = s[i:i + length] if substring in count: count[substring] += 1 else: count[substring] = 1 # If a substring occurs at least thrice, update max_length if count[substring] >= 3: max_length = max(max_length, length) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python class Solution: def maximumLength(self, s: str) -> int: count = {} for char in s: if char in count: count[char] += 1 else: count[char] = 1 max_length = -1 for char, freq in count.items(): if freq >= 3: max_length = max(max_length, len(char) * (freq // 3)) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python class Solution: def maximumLength(self, s: str) -> int: max_length = -1 for char in set(s): count = 0 current_length = 0 for c in s: if c == char: current_length += 1 else: current_length = 0 if current_length > 0: count += 1 if count >= 3: max_length = max(max_length, current_length) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| Qwen2-72B-Instruct | ```python class Solution: def maximumLength(self, s: str) -> int: max_len = -1 i = 0 while i < len(s): count = 1 j = i + 1 while j < len(s) and s[j] == s[i]: count += 1 j += 1 k = i + 1 while k < len(s) - count + 1: if s[k:k+count] == s[i:i+count]: max_len = max(max_len, count) k += 1 i = j return max_len ``` ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| baichuan4 | ```python class Solution: def maximumLength(self, s: str) -> int: from collections import Counter # Count the frequency of each character in the string char_count = Counter(s) # Filter out characters that appear less than 3 times special_chars = [char for char, count in char_count.items() if count >= 3] # The longest special substring is the one with the most frequent character if special_chars: return max(special_chars, key=lambda char: char_count[char]) else: return -1 ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| doubao | ```python class Solution: def maximumLength(self, s: str) -> int: max_length = -1 char_count = {} for i in range(len(s)): char = s[i] if char in char_count: char_count[char] += 1 else: char_count[char] = 1 if char_count[char] == 3: max_length = max(max_length, 1) for j in range(i + 1, len(s)): if s[j] == char: char_count[char] += 1 if char_count[char] == 3: max_length = max(max_length, j - i + 1) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def maximumLength(self, s: str) -> int: n = len(s) for L in range(n, 0, -1): for c in 'abcdefghijklmnopqrstuvwxyz': count = 0 substr = c * L for i in range(n - L + 1): if s[i] == c and s[i:i+L] == substr: count += 1 if count >= 3: return L return -1 ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| kimi | ```python class Solution: def maximumLength(self, s: str) -> int: from collections import Counter counter = Counter(s) max_length = -1 for char, count in counter.items(): if count >= 3: max_length = max(max_length, len(s.split(char)[0])) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| minimax | ```python class Solution: def maximumLength(self, s: str) -> int: # Dictionary to store the count of each special substring special_substring_count = {} max_length = -1 # Iterate through the string to find special substrings for i in range(len(s)): # Check if the current character is the same as the previous one if i > 0 and s[i] == s[i - 1]: # If it is, we extend the current special substring if s[i] in special_substring_count: special_substring_count[s[i]] += 1 else: special_substring_count[s[i]] = 2 else: # If it's not, we start a new special substring special_substring_count[s[i]] = 1 # Check the count of each special substring for substring, count in special_substring_count.items(): if count >= 3: # Update max_length if the current special substring is longer max_length = max(max_length, len(substring)) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| wenxinyiyan | ```python class Solution: def maximumLength(self, s: str) -> int: n = len(s) max_length = -1 # Iterate over all possible substrings for i in range(n): for j in range(i + 1, n + 1): substring = s[i:j] # Check if the substring is special and occurs at least thrice if len(set(substring)) == 1 and s.count(substring) >= 3: max_length = max(max_length, len(substring)) return max_length ``` **Explanation**: The given solution uses a nested loop to iterate over all possible substrings of the input string `s`. For each substring, it checks if it is special (i.e., made up of only a single character) and occurs at least thrice in the string. If both conditions are satisfied, it updates the `max_length` variable with the length of the substring if it is greater than the current `max_length`. Finally, it returns the `max_length` as the result. If no special substring occurs at least thrice, the initial value of `max_length` (-1) will be returned. Note: Although this solution is correct, it has a time complexity of O(n^4) due to the nested loops and the `count()` method, which can be slow for long strings. There might be more efficient solutions possible, but this one satisfies the given constraints. |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| zhipu | ```python class Solution: def maximumLength(self, s: str) -> int: from collections import defaultdict # Dictionary to store the frequency of each character sequence freq = defaultdict(int) # Populate the frequency dictionary i = 0 while i < len(s): char = s[i] j = i while j < len(s) and s[j] == char: j += 1 length = j - i freq[char, length] += 1 i = j # Find the maximum length of a special substring that occurs at least thrice max_length = -1 for (char, length), count in freq.items(): if count >= 3: max_length = max(max_length, length) return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |
| deepseek-v3 | ```python class Solution: def maximumLength(self, s: str) -> int: from collections import defaultdict # Create a dictionary to store the counts of special substrings special_counts = defaultdict(int) # Iterate over all possible starting points of the substring for i in range(len(s)): # Start with the current character current_char = s[i] # Initialize the length of the special substring length = 1 # Increment the count for the current substring special_counts[(current_char, length)] += 1 # Extend the substring to the right as long as the characters are the same for j in range(i + 1, len(s)): if s[j] == current_char: length += 1 special_counts[(current_char, length)] += 1 else: break # Now, find the maximum length of a special substring that occurs at least thrice max_length = -1 for (char, length), count in special_counts.items(): if count >= 3 and length > max_length: max_length = length return max_length ``` |
[{"input": "\"aaaa\"", "output": "2", "testtype": "functional"}, {"input": "\"abcdef\"", "output": "-1", "testtype": "functional"}, {"input": "\"abcaba\"", "output": "1", "testtype": "functional"}] |