結果
問題 | No.1268 Fruit Rush 2 |
ユーザー |
![]() |
提出日時 | 2020-10-23 23:19:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 369 ms / 2,000 ms |
コード長 | 739 bytes |
コンパイル時間 | 543 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 151,664 KB |
最終ジャッジ日時 | 2024-07-21 13:12:58 |
合計ジャッジ時間 | 7,830 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
import sysinput = sys.stdin.readlineN = 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 = 1for i in range(len(even) - 1)[::-1]:if even[i+1] == even[i] + 2:cnt += 1else:cnt = 1cnt_even[even[i]] = cntcnt_odd = {}cnt = 1for i in range(len(odd) - 1)[::-1]:if odd[i+1] == odd[i] + 2:cnt += 1else:cnt = 1cnt_odd[odd[i]] = cntans = Nfor 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)