結果
| 問題 |
No.2199 lower_bound and upper_bound
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:24:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,308 bytes |
| コンパイル時間 | 191 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 259,456 KB |
| 最終ジャッジ日時 | 2025-06-12 15:24:47 |
| 合計ジャッジ時間 | 4,833 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 TLE * 1 -- * 12 |
ソースコード
MOD = 998244353
def main():
import sys
input = sys.stdin.read
N, L, U = map(int, input().split())
# Transform variables
C = [U + i for i in range(1, N+1)]
# We need to compute the number of non-decreasing sequences E_1 <= E_2 <= ... <= E_N
# where E_i <= C[i-1] (since C is 0-based now), E_0 = 0, and E_N >= L + N
# The maximum E_N can be C[-1]
max_e = C[-1]
target = L + N
if target > max_e:
print(0)
return
# The problem reduces to counting the number of non-decreasing sequences E_0=0 <= E_1 <= ... <= E_N <= max_e
# with E_i <= C[i-1] for each i, and E_N >= target
# The solution is to compute the number of such sequences as the inclusion-exclusion over the constraints
# However, for large N, this is computationally intensive, so we need a mathematical approach
# The number of valid sequences is the product of (C_i + 1) minus the invalid sequences.
# However, this is not directly applicable, so we use a combinatorial approach with stars and bars
# The number of valid sequences can be computed using the inclusion-exclusion principle, but for large N, we need a formula
# The correct approach involves using dynamic programming with optimized prefix sums
# We will use dp[i][j] to represent the number of ways to reach j after i steps
# However, given the constraints, we can compute the result using combinatorial mathematics
# The number of valid sequences is the product of (C_i + 1) for i in 1..N, minus the sequences where any E_i exceeds C_i
# This is not straightforward, so we use the following approach:
# The number of valid sequences is the sum over all possible E_N of the number of ways to reach E_N >= target, with E_i <= C_i for all i
# To compute this, we can use dynamic programming with prefix sums
# Initialize dp array
dp = [0]*(max_e + 1)
dp[0] = 1 # E_0 = 0
for i in range(N):
# Compute the new dp array
new_dp = [0]*(max_e + 1)
# For each possible E_i, update the new_dp
for e in range(0, max_e +1):
if dp[e] == 0:
continue
# The next E_{i+1} can be from e to min(C[i], max_e)
# Since E_{i+1} >= e and E_{i+1} <= C[i]
# Also, E_{i+1} <= max_e
min_next = e
max_next = min(C[i], max_e)
if min_next > max_next:
continue
# The number of ways to transition from e is 1 for each possible next_e
# So, we add dp[e] to new_dp[min_next..max_next]
# To do this efficiently, we can use prefix sums
new_dp[min_next] = (new_dp[min_next] + dp[e]) % MOD
if max_next + 1 <= max_e:
new_dp[max_next + 1] = (new_dp[max_next + 1] - dp[e]) % MOD
# Compute the prefix sums to get the new_dp values
current = 0
for e in range(max_e +1):
current = (current + new_dp[e]) % MOD
new_dp[e] = current
dp = new_dp
# Now, sum dp[target ... max_e]
total = 0
for e in range(target, max_e +1):
total = (total + dp[e]) % MOD
print(total % MOD)
if __name__ == '__main__':
main()
gew1fw