結果

問題 No.2008 Super Worker
ユーザー AkariAkari
提出日時 2022-07-15 21:48:16
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 874 ms / 2,000 ms
コード長 1,620 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 140,016 KB
最終ジャッジ日時 2023-09-10 01:19:30
合計ジャッジ時間 14,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,236 KB
testcase_01 AC 74 ms
71,112 KB
testcase_02 AC 74 ms
71,252 KB
testcase_03 AC 75 ms
71,260 KB
testcase_04 AC 75 ms
71,116 KB
testcase_05 AC 73 ms
71,272 KB
testcase_06 AC 73 ms
71,328 KB
testcase_07 AC 75 ms
71,236 KB
testcase_08 AC 74 ms
71,252 KB
testcase_09 AC 74 ms
71,136 KB
testcase_10 AC 75 ms
71,132 KB
testcase_11 AC 72 ms
71,228 KB
testcase_12 AC 73 ms
71,464 KB
testcase_13 AC 126 ms
77,976 KB
testcase_14 AC 103 ms
77,684 KB
testcase_15 AC 99 ms
77,300 KB
testcase_16 AC 100 ms
77,232 KB
testcase_17 AC 108 ms
77,508 KB
testcase_18 AC 106 ms
77,464 KB
testcase_19 AC 96 ms
76,472 KB
testcase_20 AC 103 ms
77,460 KB
testcase_21 AC 100 ms
77,236 KB
testcase_22 AC 96 ms
76,884 KB
testcase_23 AC 869 ms
139,876 KB
testcase_24 AC 836 ms
140,016 KB
testcase_25 AC 852 ms
139,776 KB
testcase_26 AC 824 ms
139,884 KB
testcase_27 AC 852 ms
139,864 KB
testcase_28 AC 843 ms
128,860 KB
testcase_29 AC 793 ms
128,704 KB
testcase_30 AC 782 ms
128,832 KB
testcase_31 AC 785 ms
128,724 KB
testcase_32 AC 846 ms
128,692 KB
testcase_33 AC 385 ms
131,176 KB
testcase_34 AC 874 ms
128,940 KB
testcase_35 AC 278 ms
131,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
# import numpy as np

def cmp(a, b):
    a1, b1 = a
    a2, b2 = b
    return a1 + a2 * b1 >= a2 + a1 * b2


def argsort(A):
    n = len(A)
    length = 20
    INF = [1 << 60, 0]
    index = list(range(n))
    work = [0] * n
    for l in range(0, n, length):
        r = min(l + length, n)
        for i in range(l+1, r):
            if cmp(A[index[i-1]], A[index[i]]): continue
            tmp = index[i]
            a = A[tmp]
            j = i
            while j > l and not cmp(A[index[j-1]], a):
                index[j] = index[j-1]
                j -= 1
            index[j] = tmp
    while length < n:
        work = index[:]
        for l in range(0, n, 2 * length):
            li, ri = l, min(l + length, n)
            l_max, r_max = min(li + length, n), min(ri + length, n)
            tot = (l_max - li) + (r_max - ri)
            for i in range(l, l+tot):
                a = A[work[li]] if li < l_max else INF
                b = A[work[ri]] if ri < r_max else INF
                if cmp(a, b):
                    index[i] = work[li]
                    li += 1
                else:
                    index[i] = work[ri]
                    ri += 1
        length <<= 1
    return index





def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    AB = [[a, b] for a, b in zip(A, B)]
    x = 1
    ans = 0
    mod = 1_000_000_007
    idx = argsort(AB)
    for i in idx:
        a, b = AB[i]
        ans += a * x
        ans %= mod
        x *= b
        x %= mod
    print(ans)
    
    

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