結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー lam6er
提出日時 2025-04-15 21:53:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,027 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 81,616 KB
実行使用メモリ 53,756 KB
最終ジャッジ日時 2025-04-15 21:55:12
合計ジャッジ時間 4,129 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 47 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7

N = int(input())
c = list(map(int, input().split()))  # c[0] is c_1, c[1] is c_2, ..., c[8] is c_9

count_non_zero = 0
d = -1
for i in range(9):
    if c[i] > 0:
        count_non_zero += 1
        d = i + 1  # since c[i] corresponds to digit (i+1)

if count_non_zero == 1 and c[d-1] == N:
    # Compute d * (10^N - 1)/9 mod MOD
    mod9_mod = 9 * MOD
    pow_10 = pow(10, N, mod9_mod)
    pow_10_minus_1 = (pow_10 - 1) % mod9_mod
    x = pow_10_minus_1 // 9
    res = (d * x) % MOD
    print(res)
else:
    # Check if all digits are even
    all_even = True
    for i in range(9):
        if c[i] > 0 and (i + 1) % 2 != 0:
            all_even = False
            break
    
    # Compute sum_S
    sum_S = 0
    for i in range(9):
        sum_S += (i + 1) * c[i]
    
    # Compute the maximum exponent a of 3 dividing sum_S
    a = 0
    temp = sum_S
    while temp % 3 == 0 and temp != 0:
        a += 1
        temp = temp // 3
    
    product = (2 if all_even else 1) * (3 ** a)
    print(product % MOD)
0