結果

問題 No.1268 Fruit Rush 2
ユーザー trineutrontrineutron
提出日時 2020-10-23 23:02:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 304 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 10,584 KB
実行使用メモリ 42,736 KB
最終ジャッジ日時 2023-09-28 17:41:35
合計ジャッジ時間 9,009 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,976 KB
testcase_01 AC 16 ms
7,860 KB
testcase_02 AC 16 ms
7,996 KB
testcase_03 AC 16 ms
7,880 KB
testcase_04 AC 16 ms
7,884 KB
testcase_05 AC 15 ms
7,808 KB
testcase_06 AC 16 ms
7,924 KB
testcase_07 AC 16 ms
7,876 KB
testcase_08 AC 16 ms
7,812 KB
testcase_09 AC 16 ms
7,880 KB
testcase_10 AC 16 ms
7,820 KB
testcase_11 AC 16 ms
7,820 KB
testcase_12 AC 16 ms
7,792 KB
testcase_13 AC 15 ms
7,812 KB
testcase_14 AC 16 ms
7,924 KB
testcase_15 AC 16 ms
7,876 KB
testcase_16 AC 303 ms
25,796 KB
testcase_17 AC 257 ms
24,016 KB
testcase_18 AC 271 ms
24,804 KB
testcase_19 AC 270 ms
24,832 KB
testcase_20 AC 265 ms
24,460 KB
testcase_21 AC 256 ms
24,516 KB
testcase_22 AC 301 ms
26,824 KB
testcase_23 AC 307 ms
27,168 KB
testcase_24 AC 267 ms
24,820 KB
testcase_25 AC 267 ms
24,272 KB
testcase_26 AC 412 ms
37,132 KB
testcase_27 AC 412 ms
35,912 KB
testcase_28 AC 412 ms
36,160 KB
testcase_29 AC 411 ms
37,056 KB
testcase_30 AC 412 ms
35,972 KB
testcase_31 AC 450 ms
37,868 KB
testcase_32 AC 431 ms
37,932 KB
testcase_33 AC 371 ms
42,736 KB
testcase_34 AC 314 ms
35,968 KB
testcase_35 AC 346 ms
39,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
dp = {}
for i in range(n):
    if a[i] not in dp:
        dp[a[i]] = 0
    if i >= 1 and a[i] == a[i - 1] + 1:
        dp[a[i]] += 1
    if i >= 2 and a[i] - 2 in dp:
        dp[a[i]] += dp[a[i] - 2]
    ans += dp[a[i]] + 1
print(ans)
0