結果

問題 No.2519 Coins in Array
ユーザー MasKoaTSMasKoaTS
提出日時 2023-08-31 16:03:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 114,136 KB
最終ジャッジ日時 2023-09-05 16:52:54
合計ジャッジ時間 10,429 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
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 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# random

import sys, random
from math import gcd
from itertools import permutations
from collections import deque
input = sys.stdin.readline

def f(x, y):
    if(gcd(x, y) == 1):
        return (x - 1) * (y - 1)
    return 0


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

ans = 10 ** 18
ops = []
if(n == 2):
    ans = f(a[0], a[1])
    ops = [(a[0], a[1])]
elif(n == 3):
    for p in permutations(a):
        x = f(p[0], p[1]);  y = f(x, p[2])
        if(ans >= y):
            ans = y
            ops = [(p[0], p[1]), (x, p[2])]
        x = f(p[1], p[2]);  y = f(x, p[0])
        if(ans >= y):
            ans = y
            ops = [(p[1], p[2]), (x, p[0])]
else:
    que = deque(a)
    for i in range(n - 1):
        if(i % 50000 == 0):
            random.shuffle(que)
        x, y = que.popleft(), que.popleft()
        que.append(f(x, y))
        ops.append((x, y))
    ans = que.popleft()

print(ans)
for x, y in ops:
    print(x, y)
0