結果
問題 |
No.1632 Sorting Integers (GCD of M)
|
ユーザー |
|
提出日時 | 2023-12-20 22:58:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 846 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 54,952 KB |
最終ジャッジ日時 | 2024-09-27 10:14:11 |
合計ジャッジ時間 | 4,017 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 WA * 43 |
ソースコード
from math import gcd import itertools MOD = 10**9 + 7 n = int(input()) A = list(map(int, input().split())) if max(A) == n: c = A.index(n) + 1 ans = (pow(10, n, MOD * 9) - 1) // 9 * c print(ans % MOD) elif n <= 5: C = [] for i, a in enumerate(A, 1): C += [i] * a G = [] for P in itertools.permutations(C): x = 0 for p in P: x = 10 * x + p G.append(x) x = G[0] for g in G: x = gcd(x, g) print(x) else: G = [] for i in range(1, 10): for j in range(i + 1, 10): if A[i - 1] > 0 and A[j - 1] > 0: G.append((10 * j + i) - (10 * i + j)) G.append((100 * j + i) - (100 * i + j)) G.append((1000 * j + i) - (1000 * i + j)) x = G[0] for g in G: x = gcd(x, g) print(x)