結果
問題 | No.2519 Coins in Array |
ユーザー | rlangevin |
提出日時 | 2023-10-27 23:00:49 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,759 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 82,400 KB |
実行使用メモリ | 106,844 KB |
最終ジャッジ日時 | 2024-09-25 15:01:20 |
合計ジャッジ時間 | 6,994 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,016 KB |
testcase_01 | AC | 46 ms
54,144 KB |
testcase_02 | AC | 44 ms
53,984 KB |
testcase_03 | AC | 42 ms
54,272 KB |
testcase_04 | AC | 42 ms
53,816 KB |
testcase_05 | AC | 42 ms
54,528 KB |
testcase_06 | AC | 42 ms
54,272 KB |
testcase_07 | WA | - |
testcase_08 | AC | 41 ms
55,052 KB |
testcase_09 | AC | 42 ms
55,204 KB |
testcase_10 | AC | 42 ms
54,464 KB |
testcase_11 | AC | 43 ms
55,008 KB |
testcase_12 | AC | 42 ms
55,144 KB |
testcase_13 | WA | - |
testcase_14 | AC | 42 ms
54,852 KB |
testcase_15 | AC | 42 ms
54,780 KB |
testcase_16 | WA | - |
testcase_17 | AC | 42 ms
54,052 KB |
testcase_18 | AC | 42 ms
54,284 KB |
testcase_19 | AC | 42 ms
54,172 KB |
testcase_20 | AC | 42 ms
55,404 KB |
testcase_21 | AC | 43 ms
54,516 KB |
testcase_22 | AC | 43 ms
54,632 KB |
testcase_23 | AC | 156 ms
106,644 KB |
testcase_24 | AC | 161 ms
106,072 KB |
testcase_25 | AC | 42 ms
54,528 KB |
testcase_26 | AC | 42 ms
53,888 KB |
testcase_27 | AC | 160 ms
106,288 KB |
testcase_28 | AC | 159 ms
106,704 KB |
testcase_29 | AC | 156 ms
106,844 KB |
testcase_30 | AC | 149 ms
102,984 KB |
testcase_31 | AC | 81 ms
79,812 KB |
testcase_32 | AC | 111 ms
90,624 KB |
testcase_33 | AC | 131 ms
96,932 KB |
testcase_34 | AC | 98 ms
85,400 KB |
testcase_35 | AC | 127 ms
94,844 KB |
testcase_36 | AC | 90 ms
83,212 KB |
testcase_37 | AC | 83 ms
78,016 KB |
testcase_38 | AC | 117 ms
92,340 KB |
testcase_39 | AC | 96 ms
84,472 KB |
testcase_40 | AC | 150 ms
104,448 KB |
ソースコード
from math import * from copy import * inf = 10 ** 18 def f(x, y): if gcd(x, y) != 1: return 0 v = (x - 1) * (y - 1) if v >= inf: return -1 return v N = int(input()) A = list(map(int, input().split())) if N == 2: print(f(A[0], A[1])) print(1, 2) elif N == 3: v = inf T = [(1, 2), (1, 2)], [(1, 3), (1, 2)] ans = [] for tt in T: D = deepcopy(A) for t in tt: temp = f(D[t[0] - 1], D[t[1] - 1]) D.pop(t[1] - 1) D.pop(t[0] - 1) if temp == -1: break D.append(temp) else: if D[0] < v: ans = tt v = D[0] print(v) for a, b in ans: print(a, b) else: def f1(A , ans=[]): ind1, ind2 = -1, -1 N = len(A) for i in range(N): if ind1 == -1: if A[i]%2 == 0: ind1 = i + 1 else: if A[i]%2 == 0: ind2 = i + 1 if ind2 != -1: print(0) for a, b in ans: print(a, b) print(ind1, ind2) for i in range(N - 1, 1, -1): print(1, i) exit() def f2(A): ind1, ind2 = -1, -1 N = len(A) for i in range(N): if ind1 == -1: if A[i]%2 == 1: ind1 = i + 1 else: if A[i]%2 == 1: ind2 = i + 1 v = (A.pop(ind2 - 1) - 1) * (A.pop(ind1 - 1) - 1) A.append(v) return (ind1, ind2), A f1(A) t, A = f2(A) ans = [t] f1(A, ans) t, A = f2(A) ans.append(t) f1(A, ans)