結果

問題 No.1419 Power Moves
ユーザー tamatotamato
提出日時 2021-03-05 22:32:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,836 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 78,336 KB
最終ジャッジ日時 2024-04-16 10:18:17
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,864 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 41 ms
52,352 KB
testcase_04 AC 42 ms
52,608 KB
testcase_05 AC 42 ms
52,480 KB
testcase_06 AC 42 ms
52,224 KB
testcase_07 AC 42 ms
52,224 KB
testcase_08 AC 41 ms
52,224 KB
testcase_09 AC 80 ms
77,952 KB
testcase_10 AC 60 ms
63,360 KB
testcase_11 AC 63 ms
66,176 KB
testcase_12 AC 82 ms
77,440 KB
testcase_13 AC 79 ms
77,184 KB
testcase_14 AC 79 ms
78,080 KB
testcase_15 AC 78 ms
78,336 KB
testcase_16 AC 79 ms
77,696 KB
testcase_17 AC 41 ms
52,224 KB
testcase_18 AC 41 ms
52,224 KB
testcase_19 AC 41 ms
52,224 KB
testcase_20 AC 81 ms
77,824 KB
testcase_21 AC 84 ms
77,824 KB
testcase_22 AC 82 ms
77,952 KB
testcase_23 AC 80 ms
77,696 KB
testcase_24 AC 84 ms
77,824 KB
testcase_25 AC 81 ms
77,696 KB
testcase_26 AC 83 ms
77,824 KB
testcase_27 AC 81 ms
77,696 KB
testcase_28 AC 81 ms
77,952 KB
testcase_29 AC 83 ms
77,696 KB
testcase_30 AC 82 ms
77,696 KB
testcase_31 AC 83 ms
78,208 KB
testcase_32 AC 79 ms
77,824 KB
testcase_33 AC 81 ms
77,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


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

    N, K = map(int, input().split())

    ans = [0] * N
    inv2 = pow(pow(2, K, mod), mod-2, mod)
    if N%2 == 0:
        pow2_N = (pow(2, K, N) - 1)%N
        r = (pow2_N + 1) // 2
        num = ((pow(2, K-1, mod) - r)%mod * pow((N // 2), mod-2, mod))%mod
        for i in range(N):
            if i & 1:
                if i <= pow2_N:
                    ans[i] = ((num + 1) * inv2)%mod
                else:
                    ans[i] = (num * inv2)%mod
        ans_rev = [0] * N
        for i in range(1, N):
            ans_rev[i] = ans[-i]
        for i in range(N):
            ans[i] = (ans[i] + ans_rev[i])%mod
    else:
        pow2_N = (pow(2, K, N) - 1)%N
        if pow2_N & 1:
            r = (pow2_N + 1) // 2
        else:
            r = (N+1) // 2 + pow2_N // 2
        num = ((pow(2, K - 1, mod) - r) % mod * pow(N, mod - 2, mod)) % mod
        for i in range(N):
            if pow2_N & 1:
                if i & 1:
                    if i <= pow2_N:
                        ans[i] = ((num + 1) * inv2)%mod
                    else:
                        ans[i] = (num * inv2)%mod
                else:
                    ans[i] = (num * inv2)%mod
            else:
                if i&1:
                    ans[i] = ((num + 1) * inv2) % mod
                else:
                    if i <= pow2_N:
                        ans[i] = ((num + 1) * inv2) % mod
                    else:
                        ans[i] = (num * inv2)%mod
        ans_rev = [0] * N
        for i in range(1, N):
            ans_rev[i] = ans[-i]
        for i in range(N):
            ans[i] = (ans[i] + ans_rev[i])%mod
        ans[0] = (ans[0] * 2)%mod
    for i in range(N):
        print(ans[i])


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