結果

問題 No.2519 Coins in Array
ユーザー titiatitia
提出日時 2023-10-30 02:53:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 11,952 KB
実行使用メモリ 33,348 KB
最終ジャッジ日時 2023-10-30 02:53:33
合計ジャッジ時間 12,289 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,296 KB
testcase_01 AC 29 ms
10,296 KB
testcase_02 AC 30 ms
10,296 KB
testcase_03 AC 30 ms
10,296 KB
testcase_04 AC 30 ms
10,296 KB
testcase_05 AC 29 ms
10,296 KB
testcase_06 AC 30 ms
10,296 KB
testcase_07 AC 29 ms
10,296 KB
testcase_08 AC 30 ms
10,296 KB
testcase_09 AC 30 ms
10,296 KB
testcase_10 AC 29 ms
10,296 KB
testcase_11 AC 30 ms
10,296 KB
testcase_12 AC 30 ms
10,296 KB
testcase_13 AC 30 ms
10,296 KB
testcase_14 AC 29 ms
10,296 KB
testcase_15 AC 29 ms
10,296 KB
testcase_16 AC 29 ms
10,296 KB
testcase_17 AC 29 ms
10,296 KB
testcase_18 AC 29 ms
10,296 KB
testcase_19 AC 30 ms
10,296 KB
testcase_20 AC 30 ms
10,296 KB
testcase_21 AC 29 ms
10,296 KB
testcase_22 AC 29 ms
10,296 KB
testcase_23 AC 353 ms
33,348 KB
testcase_24 AC 354 ms
32,160 KB
testcase_25 AC 30 ms
10,296 KB
testcase_26 AC 30 ms
10,296 KB
testcase_27 AC 361 ms
33,348 KB
testcase_28 AC 359 ms
33,348 KB
testcase_29 AC 356 ms
33,348 KB
testcase_30 AC 332 ms
30,036 KB
testcase_31 AC 81 ms
13,928 KB
testcase_32 AC 186 ms
20,648 KB
testcase_33 AC 257 ms
25,516 KB
testcase_34 AC 134 ms
17,392 KB
testcase_35 AC 236 ms
24,996 KB
testcase_36 AC 114 ms
16,228 KB
testcase_37 AC 67 ms
12,900 KB
testcase_38 AC 200 ms
22,596 KB
testcase_39 AC 129 ms
17,004 KB
testcase_40 AC 327 ms
20,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from math import gcd

N=int(input())
A=list(map(int,input().split()))

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


if N==2:
    ANS=f(A[0],A[1])
    print(ANS)
    print(1,2)
elif N==3:
    X=f(f(A[0],A[1]),A[2])
    Y=f(f(A[0],A[2]),A[1])
    Z=f(f(A[1],A[2]),A[0])

    MIN=min(X,Y,Z)

    print(MIN)
    if MIN==X:
        print(1,2)
        print(1,2)
    elif MIN==Y:
        print(1,3)
        print(1,2)
    else:
        print(2,3)
        print(1,2)
else:
    print(0)
    O=[]
    E=[]

    for i in range(N):
        if A[i]%2==1:
            O.append(i)
        else:
            E.append(i)

    if len(E)>=2:
        print(E[0]+1,E[1]+1)
        for i in range(N-1,1,-1):
            print(1,i)
    elif len(O)>=4:
        print(O[-1]+1,O[-2]+1)
        print(O[-3]+1,O[-4]+1)
        for i in range(N-2,1,-1):
            print(1,i)
    else:
        print(O[-1]+1,O[-2]+1)
        A.pop(O[-1])
        A.pop(O[-2])

        for i in range(len(A)):
            if A[i]%2==0:
                print(i+1,N-1)
                break

        for i in range(N-2,1,-1):
            print(1,i)
            
        
        
0