結果

問題 No.1268 Fruit Rush 2
ユーザー H3PO4H3PO4
提出日時 2022-02-06 16:34:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 322 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 139,028 KB
最終ジャッジ日時 2023-09-02 07:00:30
合計ジャッジ時間 8,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,096 KB
testcase_01 AC 68 ms
71,400 KB
testcase_02 AC 70 ms
71,068 KB
testcase_03 AC 69 ms
71,124 KB
testcase_04 AC 70 ms
71,272 KB
testcase_05 AC 70 ms
71,376 KB
testcase_06 AC 71 ms
70,868 KB
testcase_07 AC 69 ms
71,040 KB
testcase_08 AC 70 ms
71,120 KB
testcase_09 AC 69 ms
71,368 KB
testcase_10 AC 70 ms
71,096 KB
testcase_11 AC 70 ms
71,456 KB
testcase_12 AC 69 ms
71,144 KB
testcase_13 AC 71 ms
71,380 KB
testcase_14 AC 70 ms
71,272 KB
testcase_15 AC 70 ms
71,460 KB
testcase_16 AC 163 ms
127,048 KB
testcase_17 AC 153 ms
120,436 KB
testcase_18 AC 155 ms
121,364 KB
testcase_19 AC 155 ms
120,880 KB
testcase_20 AC 154 ms
121,404 KB
testcase_21 AC 153 ms
120,644 KB
testcase_22 AC 165 ms
127,108 KB
testcase_23 AC 164 ms
126,524 KB
testcase_24 AC 159 ms
121,320 KB
testcase_25 AC 154 ms
120,260 KB
testcase_26 AC 197 ms
111,552 KB
testcase_27 AC 197 ms
111,336 KB
testcase_28 AC 198 ms
111,804 KB
testcase_29 AC 200 ms
111,144 KB
testcase_30 AC 201 ms
111,124 KB
testcase_31 AC 181 ms
131,636 KB
testcase_32 AC 182 ms
131,480 KB
testcase_33 AC 165 ms
134,164 KB
testcase_34 AC 150 ms
139,028 KB
testcase_35 AC 159 ms
134,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline

N = int(input())
A = sorted(map(int, input().split()))
d = {a: i for i, a in enumerate(A)}
table2 = [0] * N
ans = N
for i in range(N - 1, -1, -1):
    if A[i] + 2 in d:
        table2[i] = table2[d[A[i] + 2]] + 1
    if A[i] - 1 in d:
        ans += table2[i] + 1
print(ans)
0