結果

問題 No.2025 Select $k$-th Submultiset
ユーザー mkawa2mkawa2
提出日時 2022-07-30 10:04:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,688 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 49,336 KB
最終ジャッジ日時 2023-09-27 11:39:14
合計ジャッジ時間 55,021 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
29,896 KB
testcase_01 AC 121 ms
29,880 KB
testcase_02 AC 152 ms
32,608 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 AC 1,906 ms
47,480 KB
testcase_06 AC 1,904 ms
46,528 KB
testcase_07 AC 1,970 ms
47,640 KB
testcase_08 AC 1,955 ms
46,856 KB
testcase_09 AC 1,975 ms
47,684 KB
testcase_10 AC 1,869 ms
47,264 KB
testcase_11 AC 1,950 ms
48,996 KB
testcase_12 AC 1,909 ms
47,192 KB
testcase_13 AC 1,896 ms
47,152 KB
testcase_14 AC 1,857 ms
46,976 KB
testcase_15 AC 1,924 ms
47,088 KB
testcase_16 AC 1,872 ms
47,120 KB
testcase_17 AC 1,869 ms
47,608 KB
testcase_18 TLE -
testcase_19 AC 1,890 ms
46,776 KB
testcase_20 AC 1,896 ms
47,308 KB
testcase_21 AC 1,872 ms
49,256 KB
testcase_22 AC 1,928 ms
47,068 KB
testcase_23 AC 1,945 ms
48,284 KB
testcase_24 AC 1,904 ms
47,172 KB
testcase_25 AC 119 ms
29,848 KB
testcase_26 AC 116 ms
29,976 KB
testcase_27 AC 118 ms
29,840 KB
testcase_28 AC 122 ms
29,872 KB
testcase_29 AC 117 ms
29,800 KB
testcase_30 AC 120 ms
29,932 KB
testcase_31 AC 121 ms
29,864 KB
testcase_32 AC 121 ms
29,864 KB
testcase_33 AC 120 ms
29,844 KB
testcase_34 AC 123 ms
29,840 KB
testcase_35 AC 119 ms
29,888 KB
testcase_36 AC 125 ms
29,968 KB
testcase_37 AC 122 ms
29,828 KB
testcase_38 AC 121 ms
29,820 KB
testcase_39 AC 121 ms
29,876 KB
testcase_40 AC 120 ms
29,908 KB
testcase_41 AC 123 ms
29,852 KB
testcase_42 AC 123 ms
29,924 KB
testcase_43 AC 121 ms
29,808 KB
testcase_44 AC 120 ms
29,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(-1, 1), (-1, 0), (-1, -1), (1, -1), (1, 1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

import numpy as np
from numpy.fft import rfft, irfft

def conv(aa, bb):
    m = len(aa)+len(bb)
    m = 1 << (m-1).bit_length()
    res = (irfft(rfft(aa, m)*rfft(bb, m))+0.5).astype("i8")
    return res[:L+1]

n, L = LI()
cc = LI()
aa = []
for c in cc:
    arr = np.zeros(L+1, dtype="i8")
    arr[:c+1] = 1
    aa.append(arr)

for i in range(n-1)[::-1]:
    aa[i] = conv(aa[i], aa[i+1])
mx = aa[0][L]
# print(aa)

for i in range(n):
    cs = np.zeros(L+2, dtype="i8")
    cs[1:] = aa[i].cumsum()
    aa[i] = cs
# print(aa)

for _ in range(II()):
    k = II()
    if k > mx:
        print(-1)
        continue
    k -= 1
    ans = [0]*n
    s = 0
    for i in range(n-1):
        l = max(0, L-(s+cc[i]))
        r = np.searchsorted(aa[i+1], k+aa[i+1][l], side="right")-1
        ans[i] = L-s-r
        s += ans[i]
        k -= aa[i+1][r]-aa[i+1][l]
        # print(l, r, s, k)
    ans[-1] = L-s
    print(*ans)
0