結果

問題 No.992 最長増加部分列の数え上げ
ユーザー qqqqqqqqqq
提出日時 2020-02-14 22:46:07
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 132,944 KB
最終ジャッジ日時 2023-07-28 18:45:32
合計ジャッジ時間 13,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,188 KB
testcase_01 AC 74 ms
71,256 KB
testcase_02 AC 76 ms
71,180 KB
testcase_03 AC 74 ms
71,264 KB
testcase_04 AC 186 ms
94,564 KB
testcase_05 AC 162 ms
92,544 KB
testcase_06 AC 207 ms
97,276 KB
testcase_07 AC 178 ms
93,888 KB
testcase_08 AC 138 ms
86,736 KB
testcase_09 AC 178 ms
93,588 KB
testcase_10 AC 204 ms
96,932 KB
testcase_11 AC 236 ms
101,280 KB
testcase_12 AC 128 ms
82,876 KB
testcase_13 AC 173 ms
93,828 KB
testcase_14 AC 174 ms
93,848 KB
testcase_15 AC 128 ms
83,232 KB
testcase_16 AC 315 ms
124,088 KB
testcase_17 AC 138 ms
86,924 KB
testcase_18 AC 168 ms
94,096 KB
testcase_19 AC 243 ms
101,012 KB
testcase_20 AC 337 ms
130,336 KB
testcase_21 AC 331 ms
130,492 KB
testcase_22 AC 330 ms
130,660 KB
testcase_23 AC 332 ms
130,412 KB
testcase_24 AC 338 ms
130,088 KB
testcase_25 AC 332 ms
130,140 KB
testcase_26 AC 377 ms
131,592 KB
testcase_27 AC 333 ms
129,848 KB
testcase_28 AC 336 ms
130,476 KB
testcase_29 AC 333 ms
129,684 KB
testcase_30 AC 256 ms
131,308 KB
testcase_31 AC 256 ms
131,128 KB
testcase_32 AC 259 ms
131,184 KB
testcase_33 AC 271 ms
131,420 KB
testcase_34 AC 258 ms
131,228 KB
testcase_35 AC 254 ms
129,324 KB
testcase_36 AC 261 ms
129,160 KB
testcase_37 AC 255 ms
129,192 KB
testcase_38 AC 254 ms
129,160 KB
testcase_39 AC 255 ms
129,332 KB
testcase_40 AC 281 ms
131,692 KB
testcase_41 AC 291 ms
131,904 KB
testcase_42 AC 272 ms
131,836 KB
testcase_43 AC 292 ms
132,204 KB
testcase_44 AC 294 ms
132,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 解説を読みました
# https://stackoverflow.com/questions/22923646/number-of-all-longest-increasing-subsequences

from bisect import bisect_left

mod = 10**9+7

n = int(input())
a = list(map(int, input().split()))

row = [float("inf")]*n
cumsum = [[0] for i in range(n)]
nums = [[] for i in range(n)]
for ai in a:
    i = bisect_left(row, ai)
    add = (row[i] == ai)
    row[i] = ai
    if i == 0:
        count = 1
    else:
        j = bisect_left(nums[i-1], -ai+1)
        count = cumsum[i-1][-1] - cumsum[i-1][j]
    if add:
        cumsum[i][-1] += count
    else:
        cumsum[i].append(cumsum[i][-1]+count)
        nums[i].append(-ai)
    cumsum[i][-1] %= mod

i = bisect_left(row, float("inf"))
ans = cumsum[i-1][-1]%mod
print(ans)
0