Submission #25905111


Source Code Expand

# -*- coding: utf-8 -*-
"""
069 - Colorful Blocks 2(★3)
https://atcoder.jp/contests/typical90/tasks/typical90_bq

"""
import sys
MOD = 10**9 + 7


def main(args):
    def pow_mod(x, y):
        if y == 0:
            return 1
        res = pow_mod(x * x % MOD, y//2)
        return res * x % MOD if y % 2 else res

    N, K = map(int, input().split())
    #N, K = 10, 2
    #N, K = 2021, 617
    ans = 1
    for i in range(1, N+1):
        if i == 1:
            ans = ans * K % MOD
        elif i == 2:
            ans = ans * (K-1) % MOD
        else:
            res = ans * pow_mod(K-2, N-2) % MOD
            print(res)
            exit(0)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission Info

Submission Time
Task 069 - Colorful Blocks 2(★3)
User kichi
Language Python (3.8.2)
Score 3
Code Size 753 Byte
Status AC
Exec Time 24 ms
Memory 9184 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 3 / 3
Status
AC × 3
AC × 52
Set Name Test Cases
Sample Sample_1.txt, Sample_2.txt, Sample_3.txt
All Corner_1.txt, Corner_2.txt, Corner_3.txt, Corner_4.txt, Corner_5.txt, Corner_6.txt, Corner_7.txt, Corner_8.txt, Corner_9.txt, Hand_01.txt, Hand_02.txt, Hand_03.txt, Hand_04.txt, Hand_05.txt, Hand_06.txt, Hand_07.txt, Hand_08.txt, Hand_09.txt, Hand_10.txt, Max_Random_01.txt, Max_Random_02.txt, Max_Random_03.txt, Max_Random_04.txt, Max_Random_05.txt, Max_Random_06.txt, Max_Random_07.txt, Max_Random_08.txt, Max_Random_09.txt, Max_Random_10.txt, Random_01.txt, Random_02.txt, Random_03.txt, Random_04.txt, Random_05.txt, Random_06.txt, Random_07.txt, Random_08.txt, Random_09.txt, Random_10.txt, Random_11.txt, Random_12.txt, Random_13.txt, Random_14.txt, Random_15.txt, Random_16.txt, Random_17.txt, Random_18.txt, Random_19.txt, Random_20.txt, Sample_1.txt, Sample_2.txt, Sample_3.txt
Case Name Status Exec Time Memory
Corner_1.txt AC 18 ms 8992 KiB
Corner_2.txt AC 24 ms 9016 KiB
Corner_3.txt AC 16 ms 9160 KiB
Corner_4.txt AC 19 ms 8872 KiB
Corner_5.txt AC 19 ms 9088 KiB
Corner_6.txt AC 21 ms 9092 KiB
Corner_7.txt AC 19 ms 9028 KiB
Corner_8.txt AC 17 ms 9088 KiB
Corner_9.txt AC 17 ms 8908 KiB
Hand_01.txt AC 19 ms 9120 KiB
Hand_02.txt AC 18 ms 8872 KiB
Hand_03.txt AC 19 ms 9040 KiB
Hand_04.txt AC 16 ms 9116 KiB
Hand_05.txt AC 21 ms 9048 KiB
Hand_06.txt AC 19 ms 9180 KiB
Hand_07.txt AC 17 ms 9152 KiB
Hand_08.txt AC 19 ms 9040 KiB
Hand_09.txt AC 19 ms 9048 KiB
Hand_10.txt AC 16 ms 8908 KiB
Max_Random_01.txt AC 19 ms 8908 KiB
Max_Random_02.txt AC 23 ms 9184 KiB
Max_Random_03.txt AC 16 ms 9088 KiB
Max_Random_04.txt AC 18 ms 9044 KiB
Max_Random_05.txt AC 17 ms 9028 KiB
Max_Random_06.txt AC 18 ms 9180 KiB
Max_Random_07.txt AC 19 ms 8904 KiB
Max_Random_08.txt AC 21 ms 9180 KiB
Max_Random_09.txt AC 18 ms 8988 KiB
Max_Random_10.txt AC 24 ms 9036 KiB
Random_01.txt AC 17 ms 8992 KiB
Random_02.txt AC 16 ms 9024 KiB
Random_03.txt AC 19 ms 9156 KiB
Random_04.txt AC 18 ms 9092 KiB
Random_05.txt AC 17 ms 9056 KiB
Random_06.txt AC 19 ms 8876 KiB
Random_07.txt AC 17 ms 9128 KiB
Random_08.txt AC 24 ms 9184 KiB
Random_09.txt AC 17 ms 8904 KiB
Random_10.txt AC 18 ms 9088 KiB
Random_11.txt AC 18 ms 8900 KiB
Random_12.txt AC 23 ms 8988 KiB
Random_13.txt AC 21 ms 8984 KiB
Random_14.txt AC 17 ms 8976 KiB
Random_15.txt AC 21 ms 9084 KiB
Random_16.txt AC 21 ms 8984 KiB
Random_17.txt AC 17 ms 9036 KiB
Random_18.txt AC 23 ms 9176 KiB
Random_19.txt AC 17 ms 9088 KiB
Random_20.txt AC 18 ms 9052 KiB
Sample_1.txt AC 18 ms 9116 KiB
Sample_2.txt AC 24 ms 8876 KiB
Sample_3.txt AC 18 ms 9020 KiB