結果
| 問題 | 
                            No.2519 Coins in Array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             MasKoaTS
                         | 
                    
| 提出日時 | 2023-08-30 14:09:53 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 809 bytes | 
| コンパイル時間 | 393 ms | 
| コンパイル使用メモリ | 81,752 KB | 
| 実行使用メモリ | 120,364 KB | 
| 最終ジャッジ日時 | 2024-06-23 12:23:07 | 
| 合計ジャッジ時間 | 10,160 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | WA * 4 | 
| other | WA * 37 | 
ソースコード
import sys
from math import gcd
from itertools import permutations
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:
    ans = 0
    ops = [(a[0], a[1]), (a[2], a[3]), (f(a[0], a[1]), f(a[2], a[3]))]
    for i in range(4, n):
        ops.append((0, a[i]))
for x, y in ops:
    print(x, y)
print(ans)
            
            
            
        
            
MasKoaTS