| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 sick.sort() total_ways = 1 prev = -1 for i in range(len(sick)): if prev == -1: left_count = sick[i] else: left_count = sick[i] - prev - 1 if i == len(sick) - 1: right_count = n - sick[i] - 1 else: right_count = sick[i + 1] - sick[i] - 1 total_ways *= self.comb(left_count + right_count, left_count) total_ways %= MOD prev = sick[i] return total_ways def comb(self, n: int, k: int) -> int: MOD = 10**9 + 7 if k > n: return 0 if k > n - k: k = n - k comb = 1 for i in range(k): comb = comb * (n - i) * pow(i + 1, MOD - 2, MOD) % MOD return comb ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| deepseek-r1 | ```python from typing import List MOD = 10**9 + 7 class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 max_fact = 10**5 # Precompute up to 1e5 as per problem constraints # Precompute factorial and inverse factorial modulo MOD fact = [1] * (max_fact + 1) for i in range(1, max_fact + 1): fact[i] = fact[i-1] * i % MOD inv_fact = [1] * (max_fact + 1) inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD) for i in range(max_fact - 1, -1, -1): inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD intervals = [] # Interval before the first sick element first = sick[0] if first > 0: m = first # Positions from 0 to first-1 intervals.append((m, 1)) # Intervals between consecutive sick elements for i in range(len(sick) - 1): a, b = sick[i], sick[i+1] m = b - a - 1 if m <= 0: continue intervals.append((m, pow(2, m-1, MOD))) # Interval after the last sick element last = sick[-1] if last < n - 1: m = (n - 1) - last # Positions from last+1 to n-1 intervals.append((m, 1)) product_poss = 1 product_inv_fact = 1 total = 0 for m, poss in intervals: product_poss = product_poss * poss % MOD product_inv_fact = product_inv_fact * inv_fact[m] % MOD total += m if total == 0: return 0 result = fact[total] * product_inv_fact % MOD result = result * product_poss % MOD return result ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: from math import comb import sys import threading def main(): mod = 10 ** 9 + 7 sick_set = set(sick) sick = sorted(sick) positions = [] prev = -1 res = 1 for s in sick: if s - prev > 1: k = s - prev -1 res = res * pow(2, k -1, mod) % mod prev = s if n - 1 - sick[-1] > 0: k = n - 1 - sick[-1] res = res * pow(2, k -1, mod) % mod print(res) threading.Thread(target=main).start() ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| gpt-4o-2024-08-06 | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 # Calculate the number of uninfected children between each pair of sick children gaps = [] for i in range(1, len(sick)): gaps.append(sick[i] - sick[i-1] - 1) # Add the gaps before the first sick child and after the last sick child if sick[0] > 0: gaps.insert(0, sick[0]) if sick[-1] < n - 1: gaps.append(n - 1 - sick[-1]) # Calculate the number of ways to infect each gap def factorial(x): result = 1 for i in range(2, x + 1): result = (result * i) % MOD return result def binomial_coefficient(n, k): if k > n: return 0 if k == 0 or k == n: return 1 num = factorial(n) denom = (factorial(k) * factorial(n - k)) % MOD return (num * pow(denom, MOD - 2, MOD)) % MOD total_ways = 1 for gap in gaps: if gap > 0: total_ways = (total_ways * factorial(gap)) % MOD return total_ways ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| Qwen2-72B-Instruct | ```python from math import factorial class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 # Add virtual elements at the beginning and end sick = [0] + sick + [n] # Calculate the number of sequences between each pair of sick children sequences = [] for i in range(1, len(sick)): gap = sick[i] - sick[i-1] - 1 if gap > 0: sequences.append(gap) # Calculate the total number of sequences total_sequences = factorial(sum(sequences)) for seq in sequences: total_sequences //= factorial(seq) # Calculate the number of ways to distribute the gaps among the sick children distribution = 1 for seq in sequences: distribution *= pow(2, seq-1, MOD) distribution %= MOD # Return the final result modulo 10^9 + 7 return (total_sequences * distribution) % MOD ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| DeepSeek-Coder-V2-Lite-Instruct | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 # Create a list to mark infected positions infected = [False] * n for pos in sick: infected[pos] = True # Calculate the number of ways to infect each child dp = [0] * n if not sick: # If no sick children, all can be infected for i in range(n): dp[i] = 1 else: # Calculate the number of ways to infect each child for i in range(n): if not infected[i]: if i == 0: dp[i] = dp[i + 1] elif i == n - 1: dp[i] = dp[i - 1] else: dp[i] = dp[i - 1] + dp[i + 1] # Calculate the total number of sequences total_sequences = 1 for i in range(n): if not infected[i]: total_sequences = (total_sequences * dp[i]) % MOD return total_sequences ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python from typing import List class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 res = 1 sick = [-1] + sick + [n] for i in range(1, len(sick)): res = (res * self.count(sick[i] - sick[i-1] - 1)) % MOD return res def count(self, n: int) -> int: if n <= 1: return 1 res = 1 for i in range(1, n+1): res = (res * i) % (10**9 + 7) return res ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 res = 1 for i in range(len(sick)): if i == 0: res = res * max(sick[i] - 0, 1) % MOD else: res = res * max(sick[i] - sick[i-1] - 1, 1) % MOD res = res * max(n - 1 - sick[-1], 1) % MOD return res ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| baichuan4 | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 dp = [0] * (n + 1) dp[0] = 1 for i in range(1, n + 1): if i in sick: dp[i] = dp[i - 1] else: dp[i] = (dp[i - 1] * 2) % MOD return dp[n] ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| doubao | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 dp = [0] * n dp[0] = 1 for i in range(1, n): if i in sick: dp[i] = 0 else: if i - 1 >= 0 and i - 1 not in sick: dp[i] += dp[i - 1] if i + 1 < n and i + 1 not in sick: dp[i] += dp[i + 1] dp[i] %= MOD return sum(dp) % MOD ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| gpto1 | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: from math import comb import sys import threading def main(): mod = 10 ** 9 + 7 sick_set = set(sick) sick = sorted(sick) positions = [] prev = -1 res = 1 for s in sick: if s - prev > 1: k = s - prev -1 res = res * pow(2, k -1, mod) % mod prev = s if n - 1 - sick[-1] > 0: k = n - 1 - sick[-1] res = res * pow(2, k -1, mod) % mod print(res) threading.Thread(target=main).start() ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| kimi | ```python from typing import List class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 dp = [0] * (n + 1) dp[0] = 1 prev = -1 for i in range(len(sick)): cur = sick[i] diff = cur - prev - 1 dp[cur + 1] = (dp[cur] + dp[cur + 1]) % MOD if diff > 0: dp[cur + 1] = (dp[cur + 1] * (diff + 1) % MOD + dp[cur + 2]) % MOD prev = cur diff = n - 1 - prev if diff > 0: dp[-1] = dp[-1] * (diff + 1) % MOD return dp[-1] ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| minimax | ```python from typing import List class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 # sick is sorted in increasing order, so we can find the gaps between infected children # and calculate the number of ways to infect the children in each gap sick.append(n) # add the last position to handle the end of the queue gaps = [] for i in range(len(sick) - 1): gaps.append(sick[i+1] - sick[i] - 1) # Calculate the total number of ways to infect the children in the gaps total_sequences = 1 for gap in gaps: if gap > 0: # For each gap, the number of ways to infect is the sum of the previous gap's ways # and the ways from the current gap. This is because we can infect either end first. total_sequences *= (gap + 1) total_sequences %= MOD return total_sequences # Example usage: # sol = Solution() # print(sol.numberOfSequence(5, [0, 4])) # Output: |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| wenxinyiyan | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 dp = [0] * n sick.append(n) # Add a sentinel value to simplify the logic prev_sick = -1 total_sequences = 1 for i in range(len(sick)): if i > 0: gap = sick[i] - prev_sick - 1 # If there is a gap between sick children, calculate the number of sequences if gap > 0: dp[i] = (2 ** gap - 1) % MOD # Update the total number of sequences total_sequences = (total_sequences * dp[i]) % MOD prev_sick = sick[i] # Handle the last gap (if any) last_gap = n - 1 - prev_sick if last_gap > 0: dp.append((2 ** last_gap - 1) % MOD) total_sequences = (total_sequences * dp[-1]) % MOD # Return the total number of sequences modulo MOD return total_sequences ``` Note: The provided solution uses dynamic programming to calculate the number of possible infection sequences. It iterates over the sick children, calculating the gaps between them and using these gaps to determine the number of sequences possible in each gap. The total number of sequences is then updated by multiplying the sequences in each gap. Finally, the result is returned modulo `10^9 + 7` to satisfy the constraint. However, please note that the provided solution assumes that the `sick` list is sorted in increasing order, as stated in the problem specification. If the input `sick` list is not sorted, you may need to add a sorting step before proceeding with the calculation. Additionally, the solution appends a sentinel value `n` to the `sick` list to simplify the logic of handling the last gap. This ensures that the last gap, if any, is also considered in the calculation. |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| zhipu | ```python class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: MOD = 10**9 + 7 # Helper function to calculate factorial % MOD def factorial(x): result = 1 for i in range(2, x + 1): result = result * i % MOD return result # Helper function to calculate x^y % MOD def mod_exp(x, y): result = 1 while y > 0: if y % 2 == 1: result = result * x % MOD x = x * x % MOD y //= 2 return result # Helper function to calculate nCr % MOD def nCr(n, r): if r > n: return 0 num = factorial(n) denom = factorial(r) * factorial(n - r) % MOD return num * mod_exp(denom, MOD - 2) % MOD # Calculate the number of non-infected children non_infected = n - len(sick) # If there are no non-infected children, return 0 if non_infected == 0: return 0 # Calculate the number of gaps between infected children gaps = [] if sick[0] > 0: gaps.append(sick[0]) for i in range(1, len(sick)): if sick[i] - sick[i - 1] > 1: gaps.append(sick[i] - sick[i - 1] - 1) if sick[-1] < n - 1: gaps.append(n - 1 - sick[-1]) # Calculate the number of possible infection sequences result = 1 for gap in gaps: result = result * nCr(non_infected, gap) % MOD non_infected -= gap return result ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |
| deepseek-v3 | ```python MOD = 10**9 + 7 def comb(n, k, factorial, inv_factorial): if k < 0 or k > n: return 0 return (factorial[n] * inv_factorial[k] % MOD) * inv_factorial[n - k] % MOD def precompute_factorials(max_n, MOD): factorial = [1] * (max_n + 1) for i in range(1, max_n + 1): factorial[i] = factorial[i-1] * i % MOD inv_factorial = [1] * (max_n + 1) inv_factorial[max_n] = pow(factorial[max_n], MOD-2, MOD) for i in range(max_n - 1, -1, -1): inv_factorial[i] = inv_factorial[i+1] * (i+1) % MOD return factorial, inv_factorial class Solution: def numberOfSequence(self, n: int, sick: List[int]) -> int: if not sick: return 0 intervals = [] prev = -1 for s in sick: if s - prev > 1: intervals.append((prev + 1, s - 1)) prev = s if prev < n - 1: intervals.append((prev + 1, n - 1)) total = 1 max_len = max([end - start + 1 for start, end in intervals] + [0]) factorial, inv_factorial = precompute_factorials(max_len, MOD) for start, end in intervals: length = end - start + 1 if length == 0: continue total = total * comb(length, length, factorial, inv_factorial) % MOD return total ``` |
[{"input": "5\n[0, 4]", "output": "4", "testtype": "functional"}, {"input": "4\n[1]", "output": "3", "testtype": "functional"}] |