結果
問題 | No.2719 Equal Inner Products in Permutation |
ユーザー |
|
提出日時 | 2024-04-05 22:35:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 1,008 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 155,168 KB |
最終ジャッジ日時 | 2024-10-01 02:45:33 |
合計ジャッジ時間 | 7,123 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
# from itertools import permutations def check(N, P): Q = list(sorted(P)) if Q != list(range(1, 3 * N + 1)): print("ERROR:", N) return l, r = 0, 0 for i in range(N): l += P[i] * P[i + N] r += P[i + N] * P[i + 2 * N] if l != r: print("ERROR:", N) return def solve(N): if N == 1: ans = [-1] return ans a, b, c = [], [], [] s = 0 if N % 3 == 1: a, b, c = [1, 2, 4, 11], [7, 9, 10, 12], [8, 5, 6, 3] s = 12 elif N % 3 == 2: a, b, c = [1, 4], [3, 6], [5, 2] s = 6 else: a, b, c = [1, 2, 9], [6, 8, 7], [3, 4, 5] s = 9 while len(a) < N: a.append(s + 1) a.append(s + 2) a.append(s + 9) b.append(s + 6) b.append(s + 8) b.append(s + 7) c.append(s + 3) c.append(s + 4) c.append(s + 5) s += 9 ans = a + b + c return ans N = int(input()) print(*solve(N))