結果
| 問題 | 
                            No.2519 Coins in Array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             MasKoaTS
                         | 
                    
| 提出日時 | 2023-08-31 16:01:52 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 949 bytes | 
| コンパイル時間 | 326 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 161,640 KB | 
| 最終ジャッジ日時 | 2024-06-23 12:23:46 | 
| 合計ジャッジ時間 | 8,014 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 4 | 
| other | WA * 19 TLE * 1 -- * 17 | 
ソースコード
# 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 % 10000 == 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)
            
            
            
        
            
MasKoaTS