結果

問題 No.1268 Fruit Rush 2
ユーザー hanyuhanyu
提出日時 2020-09-20 00:20:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 35,552 KB
最終ジャッジ日時 2023-09-06 03:42:42
合計ジャッジ時間 9,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,804 KB
testcase_01 AC 17 ms
8,184 KB
testcase_02 AC 16 ms
8,136 KB
testcase_03 AC 16 ms
8,200 KB
testcase_04 AC 17 ms
7,972 KB
testcase_05 AC 16 ms
8,252 KB
testcase_06 AC 19 ms
8,176 KB
testcase_07 AC 16 ms
8,208 KB
testcase_08 AC 16 ms
8,332 KB
testcase_09 AC 16 ms
8,296 KB
testcase_10 AC 16 ms
8,324 KB
testcase_11 AC 16 ms
8,332 KB
testcase_12 AC 16 ms
8,300 KB
testcase_13 AC 16 ms
8,272 KB
testcase_14 AC 16 ms
8,332 KB
testcase_15 AC 16 ms
8,324 KB
testcase_16 AC 344 ms
25,844 KB
testcase_17 AC 291 ms
23,208 KB
testcase_18 AC 316 ms
24,056 KB
testcase_19 AC 308 ms
24,024 KB
testcase_20 AC 303 ms
23,872 KB
testcase_21 AC 297 ms
23,408 KB
testcase_22 AC 353 ms
25,916 KB
testcase_23 AC 346 ms
25,760 KB
testcase_24 AC 313 ms
23,888 KB
testcase_25 AC 300 ms
23,688 KB
testcase_26 AC 453 ms
29,964 KB
testcase_27 AC 460 ms
30,020 KB
testcase_28 AC 477 ms
30,040 KB
testcase_29 AC 463 ms
30,756 KB
testcase_30 AC 464 ms
29,976 KB
testcase_31 AC 506 ms
30,032 KB
testcase_32 AC 486 ms
30,060 KB
testcase_33 AC 383 ms
35,552 KB
testcase_34 AC 312 ms
29,968 KB
testcase_35 AC 343 ms
35,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

odd = []
even = []
for i in range(n):
    if a[i] % 2 == 1:
        odd.append(a[i])
    else:
        even.append(a[i])

odd = sorted(odd)
even = sorted(even)
odd.append(2e18 - 1)
even.append(2e18)

oddacc = [1] * len(odd)
for i in range(1, len(odd)):
    j = len(odd) - i - 1
    if odd[j] + 2 == odd[j + 1]:
        oddacc[j] += oddacc[j + 1]

evenacc = [1] * len(even)
for i in range(1, len(even)):
    j = len(even) - i - 1
    if even[j] + 2 == even[j + 1]:
        evenacc[j] += evenacc[j + 1]
    
ans = n
it = 0
for i in range(len(odd) - 1):
    while odd[i] >= even[it]:
        it += 1
    if odd[i] + 1 == even[it]:
        ans += evenacc[it]

it = 0
for i in range(len(even) - 1):
    while even[i] >= odd[it]:
        it += 1
    if even[i] + 1 == odd[it]:
        ans += oddacc[it]

print(ans)
0