結果

問題 No.992 最長増加部分列の数え上げ
ユーザー qqqqqqqqqq
提出日時 2020-02-14 22:46:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 128,420 KB
最終ジャッジ日時 2024-04-16 02:45:01
合計ジャッジ時間 12,031 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 42 ms
52,096 KB
testcase_02 AC 42 ms
52,096 KB
testcase_03 AC 41 ms
52,224 KB
testcase_04 AC 164 ms
96,384 KB
testcase_05 AC 140 ms
91,392 KB
testcase_06 AC 185 ms
98,816 KB
testcase_07 AC 157 ms
94,464 KB
testcase_08 AC 119 ms
85,888 KB
testcase_09 AC 157 ms
94,720 KB
testcase_10 AC 181 ms
98,304 KB
testcase_11 AC 217 ms
101,248 KB
testcase_12 AC 109 ms
82,432 KB
testcase_13 AC 151 ms
94,080 KB
testcase_14 AC 154 ms
94,208 KB
testcase_15 AC 108 ms
82,432 KB
testcase_16 AC 297 ms
114,824 KB
testcase_17 AC 119 ms
85,632 KB
testcase_18 AC 152 ms
94,080 KB
testcase_19 AC 228 ms
101,504 KB
testcase_20 AC 322 ms
127,656 KB
testcase_21 AC 316 ms
127,780 KB
testcase_22 AC 315 ms
127,956 KB
testcase_23 AC 321 ms
128,300 KB
testcase_24 AC 320 ms
127,824 KB
testcase_25 AC 324 ms
127,900 KB
testcase_26 AC 363 ms
128,340 KB
testcase_27 AC 318 ms
127,948 KB
testcase_28 AC 324 ms
128,044 KB
testcase_29 AC 320 ms
127,704 KB
testcase_30 AC 244 ms
127,400 KB
testcase_31 AC 243 ms
127,916 KB
testcase_32 AC 244 ms
127,536 KB
testcase_33 AC 257 ms
128,420 KB
testcase_34 AC 246 ms
127,532 KB
testcase_35 AC 241 ms
126,384 KB
testcase_36 AC 247 ms
126,384 KB
testcase_37 AC 242 ms
126,388 KB
testcase_38 AC 242 ms
126,764 KB
testcase_39 AC 242 ms
126,584 KB
testcase_40 AC 264 ms
122,792 KB
testcase_41 AC 273 ms
123,572 KB
testcase_42 AC 254 ms
122,448 KB
testcase_43 AC 276 ms
124,080 KB
testcase_44 AC 275 ms
123,696 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