結果
問題 |
No.1632 Sorting Integers (GCD of M)
|
ユーザー |
|
提出日時 | 2023-12-20 23:02:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,199 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 54,288 KB |
最終ジャッジ日時 | 2024-09-27 10:14:26 |
合計ジャッジ時間 | 4,271 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 WA * 41 |
ソースコード
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) ans = 1 for i in range(2, x + 1): if x % i != 0: continue tot = 0 ten = 1 mod = i for j, a in enumerate(A, 1): tot += ten * (pow(10, a, mod) - 1) // 9 * j tot %= mod ten *= pow(10, a, mod) ten %= mod if tot == 0: ans = i print(ans)