結果

問題 No.856 増える演算
ユーザー maspy
提出日時 2020-04-10 02:38:12
言語 Python3
(3.8.2 + numpy 1.14.5 + scipy 1.1.0)
結果
AC  
実行時間 740 ms / 3,153 ms
コード長 1,472 Byte
コンパイル時間 47 ms
使用メモリ 39,864 KB
最終ジャッジ日時 2020-05-13 02:06:36

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 469 ms
33,744 KB
testcase_01 AC 468 ms
34,936 KB
testcase_02 AC 469 ms
33,620 KB
testcase_03 AC 469 ms
36,780 KB
testcase_04 AC 471 ms
35,464 KB
testcase_05 AC 472 ms
34,144 KB
testcase_06 AC 468 ms
34,664 KB
testcase_07 AC 469 ms
34,668 KB
testcase_08 AC 469 ms
34,140 KB
testcase_09 AC 471 ms
35,460 KB
testcase_10 AC 471 ms
36,512 KB
testcase_11 AC 467 ms
36,256 KB
testcase_12 AC 469 ms
35,724 KB
testcase_13 AC 470 ms
34,148 KB
testcase_14 AC 470 ms
34,936 KB
testcase_15 AC 471 ms
33,624 KB
testcase_16 AC 468 ms
34,944 KB
testcase_17 AC 471 ms
35,200 KB
testcase_18 AC 470 ms
35,748 KB
testcase_19 AC 471 ms
36,256 KB
testcase_20 AC 466 ms
37,104 KB
testcase_21 AC 472 ms
35,512 KB
testcase_22 AC 471 ms
33,884 KB
testcase_23 AC 487 ms
36,680 KB
testcase_24 AC 492 ms
35,356 KB
testcase_25 AC 476 ms
37,224 KB
testcase_26 AC 473 ms
34,672 KB
testcase_27 AC 477 ms
36,516 KB
testcase_28 AC 490 ms
36,144 KB
testcase_29 AC 485 ms
36,376 KB
testcase_30 AC 484 ms
36,356 KB
testcase_31 AC 482 ms
34,984 KB
testcase_32 AC 491 ms
36,424 KB
testcase_33 AC 500 ms
37,656 KB
testcase_34 AC 532 ms
35,680 KB
testcase_35 AC 509 ms
34,788 KB
testcase_36 AC 526 ms
36,052 KB
testcase_37 AC 520 ms
34,916 KB
testcase_38 AC 473 ms
37,216 KB
testcase_39 AC 503 ms
37,520 KB
testcase_40 AC 491 ms
34,092 KB
testcase_41 AC 493 ms
37,632 KB
testcase_42 AC 542 ms
35,952 KB
testcase_43 AC 491 ms
37,572 KB
testcase_44 AC 472 ms
33,640 KB
testcase_45 AC 482 ms
34,168 KB
testcase_46 AC 496 ms
37,020 KB
testcase_47 AC 491 ms
35,116 KB
testcase_48 AC 506 ms
34,040 KB
testcase_49 AC 498 ms
34,152 KB
testcase_50 AC 515 ms
36,176 KB
testcase_51 AC 529 ms
35,668 KB
testcase_52 AC 535 ms
35,684 KB
testcase_53 AC 631 ms
38,744 KB
testcase_54 AC 571 ms
36,152 KB
testcase_55 AC 632 ms
36,428 KB
testcase_56 AC 573 ms
37,944 KB
testcase_57 AC 641 ms
36,640 KB
testcase_58 AC 603 ms
36,524 KB
testcase_59 AC 691 ms
36,320 KB
testcase_60 AC 580 ms
36,456 KB
testcase_61 AC 690 ms
39,756 KB
testcase_62 AC 672 ms
37,548 KB
testcase_63 AC 490 ms
37,956 KB
testcase_64 AC 664 ms
38,796 KB
testcase_65 AC 545 ms
38,196 KB
testcase_66 AC 581 ms
37,760 KB
testcase_67 AC 617 ms
36,120 KB
testcase_68 AC 672 ms
36,844 KB
testcase_69 AC 666 ms
37,528 KB
testcase_70 AC 715 ms
37,948 KB
testcase_71 AC 673 ms
36,864 KB
testcase_72 AC 652 ms
39,024 KB
testcase_73 AC 735 ms
38,272 KB
testcase_74 AC 734 ms
36,452 KB
testcase_75 AC 740 ms
39,860 KB
testcase_76 AC 733 ms
38,544 KB
testcase_77 AC 733 ms
36,980 KB
testcase_78 AC 735 ms
39,096 KB
testcase_79 AC 733 ms
38,292 KB
testcase_80 AC 731 ms
39,864 KB
testcase_81 AC 733 ms
37,764 KB
testcase_82 AC 645 ms
36,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7


def cumprod(A, MOD=MOD):
    L = len(A)
    Lsq = int(L**.5 + 1)
    A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        A[:, n] *= A[:, n - 1]
        A[:, n] %= MOD
    for n in range(1, Lsq):
        A[n] *= A[n - 1, -1]
        A[n] %= MOD
    return A.ravel()[:L]


def power(A, n):
    prod = np.ones_like(A, np.int64)
    powA = A.copy()
    for i in range(40):
        prod[n & 1 == 1] *= powA[n & 1 == 1]
        n >>= 1
        powA **= 2
        powA %= MOD
        prod %= MOD
    return prod


def prod_1(A):
    fft = np.fft.rfft
    ifft = np.fft.irfft
    fft_len = 1 << 18
    f = np.bincount(A)
    Ff = fft(f, fft_len)
    f = np.rint(ifft(Ff ** 2, fft_len)).astype(np.int64)
    np.add.at(f, A * 2, -1)
    f >>= 1
    x = np.arange(len(f))
    x = power(x, f)
    return cumprod(x)[-1]


def prod_2(A):
    B = cumprod(A)
    x = power(B[:-1], A[1:].copy())
    return cumprod(x)[-1]


def find_min(A):
    B = np.minimum.accumulate(A)[:-1]
    C = A[1:]
    nums = np.log(B + C) + np.log(B) * C
    i = np.argmin(nums)
    b, c = int(B[i]), int(C[i])
    return (b + c) * pow(b, c, MOD) % MOD


N = int(readline())
A = np.array(read().split(), np.int64)
a, b, c = map(int, (prod_1(A), prod_2(A), find_min(A)))
answer = a * b * pow(c, MOD - 2, MOD) % MOD
print(answer)
0