結果

問題 No.2519 Coins in Array
ユーザー MasKoaTS
提出日時 2023-09-03 17:48:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 916 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 120,688 KB
最終ジャッジ日時 2024-06-23 12:24:14
合計ジャッジ時間 7,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = [0] * 2
        lis2 = [0] * 2
        b = sorted(a)[:2]
        for i in range(2):
            for j, x in enumerate(a, 1):
                if(x != b[i]):
                    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)
0