結果
| 問題 | 
                            No.2519 Coins in Array
                             | 
                    
| コンテスト | |
| ユーザー | 
                             MasKoaTS
                         | 
                    
| 提出日時 | 2023-09-03 17:50:23 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 933 bytes | 
| コンパイル時間 | 472 ms | 
| コンパイル使用メモリ | 82,648 KB | 
| 実行使用メモリ | 120,720 KB | 
| 最終ジャッジ日時 | 2024-06-23 12:24:43 | 
| 合計ジャッジ時間 | 7,156 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 33 WA * 4 | 
ソースコード
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 = [(1, 2)]
elif(n == 3):
    while(len(a) > 1):
        lis1 = [-1] * 2
        lis2 = [0] * 2
        b = sorted(a)[:2]
        for i in range(2):
            for j, x in enumerate(a, 1):
                if(x != b[i] or j == lis1[0]):
                    continue
                lis1[i] = j
                lis2[i] = x
                break
        for x in lis2:
            a.remove(x)
        a.append(f(*lis2))
        ops.append(tuple(lis1))
    ans = a[0]
else:
    ans = 0
    ops = [(1, 2), (1, 2), (n - 3, n - 2)]
    for i in range(n - 3, 1, -1):
        ops.append((1, i))
print(ans)
for x, y in ops:
    print(x, y)
            
            
            
        
            
MasKoaTS