結果

問題 No.1268 Fruit Rush 2
ユーザー sotanishysotanishy
提出日時 2020-10-23 23:19:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 162,136 KB
最終ジャッジ日時 2023-09-28 18:32:41
合計ジャッジ時間 9,938 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,292 KB
testcase_01 AC 74 ms
71,492 KB
testcase_02 AC 75 ms
71,472 KB
testcase_03 AC 74 ms
71,528 KB
testcase_04 AC 75 ms
71,288 KB
testcase_05 AC 75 ms
71,344 KB
testcase_06 AC 75 ms
71,528 KB
testcase_07 AC 75 ms
71,416 KB
testcase_08 AC 76 ms
71,360 KB
testcase_09 AC 76 ms
71,200 KB
testcase_10 AC 77 ms
71,360 KB
testcase_11 AC 75 ms
71,408 KB
testcase_12 AC 78 ms
71,200 KB
testcase_13 AC 75 ms
71,364 KB
testcase_14 AC 74 ms
71,364 KB
testcase_15 AC 73 ms
71,108 KB
testcase_16 AC 315 ms
112,280 KB
testcase_17 AC 279 ms
104,656 KB
testcase_18 AC 292 ms
106,640 KB
testcase_19 AC 300 ms
106,424 KB
testcase_20 AC 284 ms
104,816 KB
testcase_21 AC 279 ms
105,296 KB
testcase_22 AC 319 ms
112,516 KB
testcase_23 AC 319 ms
112,104 KB
testcase_24 AC 289 ms
104,792 KB
testcase_25 AC 282 ms
105,268 KB
testcase_26 AC 398 ms
142,612 KB
testcase_27 AC 420 ms
142,784 KB
testcase_28 AC 396 ms
142,852 KB
testcase_29 AC 400 ms
142,568 KB
testcase_30 AC 398 ms
142,680 KB
testcase_31 AC 385 ms
121,584 KB
testcase_32 AC 381 ms
121,648 KB
testcase_33 AC 207 ms
162,136 KB
testcase_34 AC 176 ms
124,268 KB
testcase_35 AC 187 ms
152,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
even = [10**20]
odd = [10**20]
for a in A:
    if a % 2 == 0:
        even.append(a)
    else:
        odd.append(a)
even.sort()
odd.sort()
cnt_even = {}
cnt = 1
for i in range(len(even) - 1)[::-1]:
    if even[i+1] == even[i] + 2:
        cnt += 1
    else:
        cnt = 1
    cnt_even[even[i]] = cnt
cnt_odd = {}
cnt = 1
for i in range(len(odd) - 1)[::-1]:
    if odd[i+1] == odd[i] + 2:
        cnt += 1
    else:
        cnt = 1
    cnt_odd[odd[i]] = cnt
ans = N
for a in A:
    if a % 2 == 0:
        if a + 1 in cnt_odd:
            ans += cnt_odd[a + 1]
    else:
        if a + 1 in cnt_even:
            ans += cnt_even[a + 1]
print(ans)
0