結果

問題 No.2519 Coins in Array
ユーザー ニックネームニックネーム
提出日時 2023-10-27 22:47:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 740 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 31,188 KB
最終ジャッジ日時 2024-09-25 14:48:28
合計ジャッジ時間 9,414 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
n = int(input())
a = list(map(int,input().split()))
def f(x,y): return 0 if gcd(x,y)>1 else x*y-x-y+1
if n==2: print(f(a[0],a[1])); print(1,2)
elif n==3:
    p,q,r = f(f(a[0],a[1]),a[2]),f(f(a[1],a[2]),a[0]),f(f(a[2],a[0]),a[1])
    if q>=p<=r: print(p); print(1,2); print(1,2)
    elif q<=r: print(q); print(2.3); print(1,2)
    else: print(r); print(3,1); print(1,2)
else:
    print(0); j = [[],[],[]]
    for i,v in enumerate(a): j[v%3].append(i)
    if len(j[0])==0: print(1,2); print(1,2)
    elif len(j[0])>=2: print(j[0][0]+1,j[0][1]+1); print(1,n-1)
    elif len(j[2])>=2: print(j[2][0]+1,j[2][1]+1); print(j[0][0]+1,n-1)
    else: print(j[0][0]+1,j[0][1]+1); print(1,2)
    for i in range(n-2,1,-1): print(1,i)
0