結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー tamatotamato
提出日時 2021-07-31 11:23:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,722 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 53,772 KB
最終ジャッジ日時 2023-10-21 16:18:25
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,772 KB
testcase_01 AC 41 ms
53,772 KB
testcase_02 AC 39 ms
53,772 KB
testcase_03 AC 38 ms
53,772 KB
testcase_04 AC 38 ms
53,772 KB
testcase_05 AC 38 ms
53,772 KB
testcase_06 AC 38 ms
53,772 KB
testcase_07 AC 37 ms
53,772 KB
testcase_08 AC 39 ms
53,772 KB
testcase_09 AC 38 ms
53,772 KB
testcase_10 AC 37 ms
53,772 KB
testcase_11 AC 38 ms
53,772 KB
testcase_12 AC 38 ms
53,772 KB
testcase_13 AC 38 ms
53,772 KB
testcase_14 AC 37 ms
53,772 KB
testcase_15 AC 37 ms
53,772 KB
testcase_16 AC 37 ms
53,772 KB
testcase_17 AC 37 ms
53,772 KB
testcase_18 AC 37 ms
53,772 KB
testcase_19 AC 38 ms
53,772 KB
testcase_20 AC 38 ms
53,772 KB
testcase_21 AC 38 ms
53,772 KB
testcase_22 AC 38 ms
53,772 KB
testcase_23 AC 38 ms
53,772 KB
testcase_24 AC 38 ms
53,772 KB
testcase_25 AC 39 ms
53,772 KB
testcase_26 AC 38 ms
53,772 KB
testcase_27 AC 38 ms
53,772 KB
testcase_28 AC 38 ms
53,772 KB
testcase_29 AC 38 ms
53,772 KB
testcase_30 AC 39 ms
53,772 KB
testcase_31 AC 38 ms
53,772 KB
testcase_32 AC 38 ms
53,772 KB
testcase_33 AC 39 ms
53,772 KB
testcase_34 AC 37 ms
53,772 KB
testcase_35 AC 38 ms
53,772 KB
testcase_36 AC 38 ms
53,772 KB
testcase_37 AC 38 ms
53,772 KB
testcase_38 AC 37 ms
53,772 KB
testcase_39 AC 38 ms
53,772 KB
testcase_40 AC 38 ms
53,772 KB
testcase_41 AC 37 ms
53,772 KB
testcase_42 AC 38 ms
53,772 KB
testcase_43 AC 37 ms
53,772 KB
testcase_44 AC 38 ms
53,772 KB
testcase_45 AC 37 ms
53,772 KB
testcase_46 AC 38 ms
53,772 KB
testcase_47 AC 38 ms
53,772 KB
testcase_48 AC 37 ms
53,772 KB
testcase_49 AC 38 ms
53,772 KB
testcase_50 AC 37 ms
53,772 KB
testcase_51 AC 37 ms
53,772 KB
testcase_52 AC 38 ms
53,772 KB
testcase_53 AC 38 ms
53,772 KB
testcase_54 AC 38 ms
53,772 KB
testcase_55 AC 37 ms
53,772 KB
testcase_56 AC 37 ms
53,772 KB
testcase_57 AC 38 ms
53,772 KB
testcase_58 AC 38 ms
53,772 KB
testcase_59 AC 37 ms
53,772 KB
testcase_60 AC 37 ms
53,772 KB
testcase_61 AC 37 ms
53,772 KB
testcase_62 AC 37 ms
53,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    C = [0] + list(map(int, input().split()))

    nz = [0] * 10
    for i in range(1, 10):
        if C[i]:
            nz[i] = 1
    if sum(nz) == 1:
        c = 0
        for i in range(1, 10):
            if nz[i]:
                c = i
                break
        print((c * (pow(10, N, mod) - 1) * pow(9, mod-2, mod))%mod)
        exit()

    ans = 1
    # 2
    flg2 = 1
    for i in range(1, 10):
        if i % 2 and C[i]:
            flg2 = 0
            break
    if flg2:
        ans = 2

    # 4
    flg4 = 1
    for i in range(1, 10):
        if i % 4 and C[i]:
            flg4 = 0
            break
    if flg4:
        ans = 4

    # 3, 9
    S = 0
    for i, c in enumerate(C):
        S = S + c * i
    if S % 9 == 0:
        ans *= 9
    elif S % 3 == 0:
        ans *= 3

    # 7
    T = set()
    for i in range(1, 10):
        if C[i]:
            T.add(i)
    T = sorted(list(T))
    if T == [1, 8] or T == [2, 9]:
        if N % 6 == 0:
            ans *= 7

    # 27
    mod27 = [0] * 27
    for i in range(27):
        mod27[i] = (mod27[i-1] + pow(10, i, 27)) % 27

    U = set()
    for i in range(1, 10):
        if C[i]:
            U.add(i)
    U = sorted(list(U))
    flg27 = 1
    for u1 in U:
        for u2 in U:
            if (u1 - u2) % 3:
                flg27 = 0
    if flg27:
        cnt = 0
        V = 0
        for i, c in enumerate(C):
            if c:
                V += i * (mod27[(c + cnt - 1) % 27] - mod27[(cnt - 1) % 27])
                cnt += c % 27
        if V % 27 == 0:
            ans *= 3

    print(ans)


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