結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー gew1fw
提出日時 2025-06-12 12:55:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,604 KB
実行使用メモリ 54,420 KB
最終ジャッジ日時 2025-06-12 13:00:46
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

MOD = 10**9 + 7

N = int(input())
c = list(map(int, input().split()))

# Check if all digits are the same
all_same = False
d = -1
for i in range(9):
    if c[i] == N:
        valid = True
        for j in range(9):
            if j != i and c[j] != 0:
                valid = False
                break
        if valid:
            all_same = True
            d = i + 1
            break

if all_same:
    # Compute d * (10^N - 1) / 9 mod MOD
    mod_val = 9 * MOD
    pow_10 = pow(10, N, mod_val)
    numerator = (pow_10 - 1) % mod_val
    part = (numerator // 9) % MOD
    res = (d * part) % MOD
    print(res)
else:
    sum_S = sum((i + 1) * count for i, count in enumerate(c))
    g = math.gcd(sum_S, 9)
    
    even_flag = True
    for i in range(9):
        if c[i] > 0 and (i + 1) % 2 != 0:
            even_flag = False
            break
    
    res = g * 2 if even_flag else g
    print(res % MOD)
0