結果

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

ソースコード

diff #

import math

def main():
    MOD = 10**9 + 7
    N = int(input())
    c = list(map(int, input().split()))
    
    if N == 1:
        for i in range(9):
            if c[i] == 1:
                print(i + 1)
                return
    else:
        count_nonzero = sum(1 for x in c if x > 0)
        if count_nonzero == 1:
            for i in range(9):
                if c[i] > 0:
                    d = i + 1
                    break
            pow_10 = pow(10, N, MOD)
            numerator = (pow_10 - 1) % MOD
            inv9 = 111111112  # Modular inverse of 9 mod MOD
            sum_part = (numerator * inv9) % MOD
            M = (d * sum_part) % MOD
            print(M)
            return
        else:
            a = 0
            if c[0] == 0 and c[2] == 0 and c[4] == 0 and c[6] == 0 and c[8] == 0:
                a = 1
            b = 0
            if c[4] == N:
                b = 1
            S = 0
            for i in range(9):
                S += (i + 1) * c[i]
            g = math.gcd(S, 9)
            d = (pow(2, a, MOD) * pow(5, b, MOD)) % MOD
            d = (d * g) % MOD
            print(d)

if __name__ == "__main__":
    main()
0