結果

問題 No.1268 Fruit Rush 2
ユーザー rlangevin
提出日時 2023-02-07 23:37:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 551 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 186,264 KB
最終ジャッジ日時 2024-07-05 17:07:54
合計ジャッジ時間 6,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

N = int(input())
A = list(map(int, input().split()))
E, O = [], []
for a in A:
    if a % 2:
        O.append(a)
    else:
        E.append(a)
O.sort(reverse=True)
E.sort(reverse=True)
D = defaultdict(int)
now = 1
pre = -1
for od in O:
    if od == pre - 2:
        now += 1
    else:
        now = 1
    D[od - 1] += now
    pre = od
    
now = 1
pre = -1
for ev in E:
    if ev == pre - 2:
        now += 1
    else:
        now = 1
    D[ev - 1] += now
    pre = ev
    
ans = N
for a in A:
    ans += D[a]
print(ans)    
0