結果

問題 No.2519 Coins in Array
ユーザー ShirotsumeShirotsume
提出日時 2023-09-19 13:46:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 109,864 KB
最終ジャッジ日時 2023-09-19 13:51:32
合計ジャッジ時間 10,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
74,780 KB
testcase_01 AC 113 ms
74,552 KB
testcase_02 AC 113 ms
74,596 KB
testcase_03 AC 112 ms
74,700 KB
testcase_04 AC 115 ms
74,308 KB
testcase_05 AC 117 ms
74,744 KB
testcase_06 AC 114 ms
74,524 KB
testcase_07 AC 123 ms
74,832 KB
testcase_08 AC 113 ms
74,272 KB
testcase_09 AC 113 ms
74,932 KB
testcase_10 AC 115 ms
74,852 KB
testcase_11 AC 118 ms
74,520 KB
testcase_12 AC 120 ms
74,956 KB
testcase_13 AC 119 ms
74,584 KB
testcase_14 AC 120 ms
74,520 KB
testcase_15 AC 141 ms
74,612 KB
testcase_16 AC 113 ms
74,356 KB
testcase_17 AC 114 ms
74,656 KB
testcase_18 AC 114 ms
74,668 KB
testcase_19 AC 115 ms
74,456 KB
testcase_20 AC 114 ms
74,556 KB
testcase_21 AC 110 ms
74,796 KB
testcase_22 AC 117 ms
74,468 KB
testcase_23 AC 260 ms
105,784 KB
testcase_24 AC 242 ms
104,544 KB
testcase_25 AC 112 ms
74,764 KB
testcase_26 AC 115 ms
74,768 KB
testcase_27 AC 267 ms
106,072 KB
testcase_28 AC 240 ms
105,704 KB
testcase_29 AC 244 ms
105,736 KB
testcase_30 AC 246 ms
102,604 KB
testcase_31 AC 148 ms
84,444 KB
testcase_32 AC 184 ms
95,892 KB
testcase_33 AC 207 ms
101,936 KB
testcase_34 AC 178 ms
90,200 KB
testcase_35 AC 201 ms
99,068 KB
testcase_36 AC 163 ms
88,552 KB
testcase_37 AC 147 ms
83,556 KB
testcase_38 AC 187 ms
97,040 KB
testcase_39 AC 177 ms
89,524 KB
testcase_40 AC 224 ms
109,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
import itertools
from math import gcd

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

a = li()


ans = inf
it = []
if n == 2:
    ans = f(a[0], a[1])
    it = [(1, 2)]
elif n == 3:
    for v in itertools.permutations(a):
        if ans >= f(f(v[0], v[1]), v[2]):
            one = a.index(v[0])
            a[one] = -1
            two = a.index(v[1])
            a[one] = v[0]
            it = [(one + 1, two + 1), (1, 2)]
            
            ans = min(ans, f(f(v[0], v[1]), v[2]))
else:
    ans = 0
    it = [(1, 2) for _ in range(n - 1)]
print(ans)
for v in it:
    print(*v)


0