結果

問題 No.1564 Sum of Products of Pairs
ユーザー lloyzlloyz
提出日時 2021-12-17 23:31:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 10,708 KB
実行使用メモリ 40,252 KB
最終ジャッジ日時 2023-10-13 02:52:45
合計ジャッジ時間 7,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,760 KB
testcase_01 AC 16 ms
7,792 KB
testcase_02 AC 16 ms
7,832 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 15 ms
7,804 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 16 ms
7,760 KB
testcase_29 AC 16 ms
7,748 KB
testcase_30 AC 16 ms
7,860 KB
testcase_31 AC 16 ms
7,748 KB
testcase_32 AC 15 ms
7,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
AIDX = []
for i in range(2 * n):
    AIDX.append((A[i], i))

AIDX.sort(key=lambda x: x[0], reverse=True)
for i in range(0, 2 * n, 2):
    curr_ind = AIDX[i][1]
    next_ind = AIDX[i + 1][1]
    if curr_ind // 2 == next_ind // 2:
        continue
    if curr_ind % 2 == 0:
        curr_ind_pair = curr_ind + 1
    else:
        curr_ind_pair = curr_ind - 1
    A[next_ind], A[curr_ind_pair] = A[curr_ind_pair], A[next_ind]
    break

ans = 0
for i in range(0, 2 * n, 2):
    ans += A[i] * A[i + 1]
print(ans)
0