結果
問題 | No.1555 Constructed Balancing Sequence |
ユーザー | chineristAC |
提出日時 | 2021-01-06 04:22:04 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,299 bytes |
コンパイル時間 | 373 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 851,928 KB |
最終ジャッジ日時 | 2024-06-22 19:27:20 |
合計ジャッジ時間 | 2,970 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,608 KB |
testcase_01 | AC | 97 ms
76,508 KB |
testcase_02 | AC | 40 ms
52,864 KB |
testcase_03 | AC | 39 ms
52,864 KB |
testcase_04 | AC | 40 ms
52,608 KB |
testcase_05 | AC | 39 ms
52,736 KB |
testcase_06 | AC | 39 ms
52,480 KB |
testcase_07 | AC | 40 ms
52,992 KB |
testcase_08 | AC | 40 ms
52,992 KB |
testcase_09 | AC | 50 ms
62,720 KB |
testcase_10 | AC | 40 ms
52,992 KB |
testcase_11 | AC | 55 ms
63,744 KB |
testcase_12 | MLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
ソースコード
def perferct_solve(N,K,A): mod = 998244353 diff = [A[0] for i in range(N)] S = A[0] for i in range(1,N): diff[i] = S - A[i] if diff[i] < 0: return 0 S += A[i] diff.append(0) sum_table = [0 for i in range(N)] sum_table[0] = diff[0] - diff[1] + 2*K + 1 for i in range(1,N): sum_table[i] = 2 * sum_table[i-1] + diff[i] - diff[i+1] - (2*K+1) dp = [[0 for minus in range(3*K+1)] for i in range(N)] for minus in range(3*K+1): dp_S = sum_table[0] - minus real_S = diff[1] + dp_S - 2*K - 1 first = diff[0] - minus if -K<=first<=K: dp[0][minus] = 1 if minus: dp[0][minus] += dp[0][minus-1] dp[0][minus] %= mod for i in range(1,N): sum = sum_table[i] for minus in range(3*K+1): dp_S = sum - minus real_S = dp_S + diff[i+1] - 2*K - 1 if diff[i]: L = max((real_S+minus+diff[i]+1)//2,-K+minus+diff[i]) R = min((real_S+minus+diff[i])//2,K+minus+diff[i]) if L==R: dp[i][minus] += dp[i-1][0] dp[i][minus] %= mod if minus%2==diff[i] and real_S%2==0 and -K<=real_S//2<=K: pre_minus_L = max(0,minus//2+1+diff[i]) pre_minus_R = min(3*K,minus//2+3*K+diff[i]) if pre_minus_L<=pre_minus_R: dp[i][minus] += dp[i-1][pre_minus_R] - dp[i-1][pre_minus_L-1] * (pre_minus_L>0) dp[i][minus] %= mod if diff[i]<=1 and (real_S+minus-diff[i])%2==0: m = max(0,-K+minus-diff[i]-(real_S+minus-diff[i])//2) M = min((minus-diff[i])//2,K+minus-diff[i]-(real_S+minus-diff[i])//2) pre_minus_L = max(0,m+diff[i]) pre_minus_R = min(3*K,M+diff[i]) if pre_minus_R>=pre_minus_L: dp[i][minus] += dp[i-1][pre_minus_R] - dp[i-1][pre_minus_L-1] * (pre_minus_L>0) dp[i][minus] %= mod if minus: dp[i][minus] += dp[i][minus-1] dp[i][minus] %= mod return dp[N-1][0] N,K = map(int,input().split()) A = list(map(int,input().split())) print(perferct_solve(N,K,A))