結果

問題 No.856 増える演算
ユーザー maspymaspy
提出日時 2020-04-10 02:38:12
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 776 ms / 3,153 ms
コード長 1,472 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 47,584 KB
最終ジャッジ日時 2023-10-12 06:35:57
合計ジャッジ時間 58,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 499 ms
44,488 KB
testcase_01 AC 501 ms
42,588 KB
testcase_02 AC 498 ms
42,540 KB
testcase_03 AC 501 ms
43,224 KB
testcase_04 AC 504 ms
42,584 KB
testcase_05 AC 506 ms
45,036 KB
testcase_06 AC 503 ms
44,688 KB
testcase_07 AC 507 ms
43,480 KB
testcase_08 AC 504 ms
43,868 KB
testcase_09 AC 500 ms
42,564 KB
testcase_10 AC 496 ms
44,776 KB
testcase_11 AC 498 ms
42,496 KB
testcase_12 AC 507 ms
42,736 KB
testcase_13 AC 507 ms
44,808 KB
testcase_14 AC 503 ms
42,512 KB
testcase_15 AC 509 ms
44,756 KB
testcase_16 AC 506 ms
43,364 KB
testcase_17 AC 511 ms
44,856 KB
testcase_18 AC 510 ms
43,280 KB
testcase_19 AC 499 ms
42,596 KB
testcase_20 AC 500 ms
42,596 KB
testcase_21 AC 500 ms
42,388 KB
testcase_22 AC 499 ms
44,288 KB
testcase_23 AC 512 ms
44,604 KB
testcase_24 AC 526 ms
44,464 KB
testcase_25 AC 508 ms
42,500 KB
testcase_26 AC 498 ms
42,488 KB
testcase_27 AC 491 ms
45,400 KB
testcase_28 AC 519 ms
45,160 KB
testcase_29 AC 517 ms
42,568 KB
testcase_30 AC 510 ms
45,224 KB
testcase_31 AC 508 ms
43,400 KB
testcase_32 AC 516 ms
44,108 KB
testcase_33 AC 526 ms
45,696 KB
testcase_34 AC 561 ms
45,188 KB
testcase_35 AC 542 ms
44,848 KB
testcase_36 AC 558 ms
44,228 KB
testcase_37 AC 551 ms
44,552 KB
testcase_38 AC 512 ms
42,648 KB
testcase_39 AC 513 ms
45,032 KB
testcase_40 AC 526 ms
43,368 KB
testcase_41 AC 525 ms
45,204 KB
testcase_42 AC 562 ms
43,460 KB
testcase_43 AC 524 ms
44,984 KB
testcase_44 AC 511 ms
44,472 KB
testcase_45 AC 519 ms
44,652 KB
testcase_46 AC 524 ms
45,024 KB
testcase_47 AC 519 ms
43,168 KB
testcase_48 AC 539 ms
45,424 KB
testcase_49 AC 527 ms
43,956 KB
testcase_50 AC 544 ms
44,388 KB
testcase_51 AC 560 ms
44,444 KB
testcase_52 AC 560 ms
45,332 KB
testcase_53 AC 723 ms
45,608 KB
testcase_54 AC 601 ms
47,584 KB
testcase_55 AC 665 ms
46,220 KB
testcase_56 AC 582 ms
45,456 KB
testcase_57 AC 673 ms
45,416 KB
testcase_58 AC 644 ms
45,616 KB
testcase_59 AC 733 ms
45,712 KB
testcase_60 AC 612 ms
45,936 KB
testcase_61 AC 737 ms
47,004 KB
testcase_62 AC 710 ms
46,272 KB
testcase_63 AC 530 ms
44,388 KB
testcase_64 AC 703 ms
45,848 KB
testcase_65 AC 572 ms
45,264 KB
testcase_66 AC 615 ms
46,072 KB
testcase_67 AC 647 ms
45,872 KB
testcase_68 AC 711 ms
46,652 KB
testcase_69 AC 708 ms
47,044 KB
testcase_70 AC 755 ms
46,336 KB
testcase_71 AC 710 ms
46,496 KB
testcase_72 AC 681 ms
46,488 KB
testcase_73 AC 776 ms
45,200 KB
testcase_74 AC 770 ms
45,044 KB
testcase_75 AC 770 ms
45,028 KB
testcase_76 AC 768 ms
45,104 KB
testcase_77 AC 770 ms
45,568 KB
testcase_78 AC 767 ms
45,084 KB
testcase_79 AC 768 ms
47,348 KB
testcase_80 AC 765 ms
45,208 KB
testcase_81 AC 768 ms
47,100 KB
testcase_82 AC 676 ms
45,564 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