結果

問題 No.2519 Coins in Array
ユーザー 👑 rin204rin204
提出日時 2023-10-27 21:44:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,196 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 119,584 KB
最終ジャッジ日時 2023-10-27 21:44:42
合計ジャッジ時間 8,323 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,596 KB
testcase_01 AC 35 ms
53,532 KB
testcase_02 AC 34 ms
53,532 KB
testcase_03 AC 34 ms
53,596 KB
testcase_04 AC 36 ms
53,532 KB
testcase_05 AC 35 ms
53,532 KB
testcase_06 AC 34 ms
53,596 KB
testcase_07 WA -
testcase_08 AC 35 ms
53,596 KB
testcase_09 WA -
testcase_10 AC 35 ms
53,596 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 38 ms
53,532 KB
testcase_15 AC 36 ms
53,532 KB
testcase_16 AC 37 ms
53,532 KB
testcase_17 AC 37 ms
53,532 KB
testcase_18 AC 38 ms
53,532 KB
testcase_19 WA -
testcase_20 AC 36 ms
53,532 KB
testcase_21 AC 36 ms
53,532 KB
testcase_22 AC 36 ms
53,596 KB
testcase_23 AC 179 ms
119,584 KB
testcase_24 AC 163 ms
119,496 KB
testcase_25 WA -
testcase_26 AC 36 ms
53,536 KB
testcase_27 AC 161 ms
106,392 KB
testcase_28 AC 158 ms
106,392 KB
testcase_29 AC 152 ms
106,396 KB
testcase_30 AC 151 ms
112,784 KB
testcase_31 AC 76 ms
78,856 KB
testcase_32 AC 110 ms
94,188 KB
testcase_33 AC 130 ms
104,144 KB
testcase_34 AC 96 ms
87,528 KB
testcase_35 AC 123 ms
100,656 KB
testcase_36 AC 86 ms
83,884 KB
testcase_37 AC 68 ms
77,844 KB
testcase_38 AC 115 ms
97,376 KB
testcase_39 AC 94 ms
85,788 KB
testcase_40 AC 154 ms
117,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd


def f(a, b):
    if gcd(a, b) == 1:
        return a * b - a - b + 1
    else:
        return 0


n = int(input())
A = list(map(int, input().split()))
odd = []
even = []
for i, a in enumerate(A):
    if a % 2 == 1:
        odd.append(i)
    else:
        even.append(i)

if len(even) >= 2:
    i, j = even[:2]
    print(0)
    print(i + 1, j + 1)
    for i in range(n - 2, 0, -1):
        print(i, i + 1)
    exit()
elif even and len(odd) >= 2:
    i, j = odd[:2]
    print(0)
    print(i + 1, j + 1)
    ii = even[0]
    if i < ii:
        ii += 1
    if j < ii:
        ii += 1
    print(ii + 1, n - 1)
    for i in range(n - 3, 0, -1):
        print(i, i + 1)
elif len(odd) >= 4:
    i, j, k, l = odd[:4]
    print(0)
    print(k + 1, l + 1)
    print(i + 1, j + 1)
    print(n - 3, n - 2)
    for i in range(n - 4, 0, -1):
        print(i, i + 1)
elif n == 2:
    a, b = A
    print(f(a, b))
    print(1, 2)
else:
    a, b, c = A
    mi1 = f(f(a, b), c)
    mi2 = f(f(a, c), b)
    mi3 = f(f(b, c), a)
    mi = min(mi1, mi2, mi3)
    print(mi1)
    if mi == mi1:
        print(1, 2)
    elif mi == mi2:
        print(1, 3)
    else:
        print(2, 3)
    print(1, 2)
0