結果

問題 No.2025 Select $k$-th Submultiset
ユーザー mkawa2mkawa2
提出日時 2022-07-30 10:08:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,701 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 50,276 KB
最終ジャッジ日時 2023-09-27 11:44:41
合計ジャッジ時間 55,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
29,764 KB
testcase_01 AC 138 ms
29,820 KB
testcase_02 AC 140 ms
30,724 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 1,990 ms
38,484 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 AC 1,993 ms
39,016 KB
testcase_12 TLE -
testcase_13 AC 1,967 ms
37,664 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 1,995 ms
38,328 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 138 ms
29,884 KB
testcase_26 AC 140 ms
29,920 KB
testcase_27 AC 138 ms
29,872 KB
testcase_28 AC 140 ms
29,892 KB
testcase_29 AC 138 ms
29,880 KB
testcase_30 AC 139 ms
29,840 KB
testcase_31 AC 138 ms
29,880 KB
testcase_32 AC 132 ms
29,916 KB
testcase_33 AC 139 ms
29,916 KB
testcase_34 AC 138 ms
29,856 KB
testcase_35 AC 132 ms
29,932 KB
testcase_36 AC 146 ms
30,076 KB
testcase_37 AC 142 ms
29,940 KB
testcase_38 AC 138 ms
29,992 KB
testcase_39 AC 131 ms
29,896 KB
testcase_40 AC 137 ms
29,884 KB
testcase_41 AC 133 ms
29,908 KB
testcase_42 AC 137 ms
29,972 KB
testcase_43 AC 130 ms
29,912 KB
testcase_44 AC 138 ms
29,788 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[:min(len(aa)+len(bb)-1,L+1)]

n, L = LI()
cc = LI()
aa = []
for c in cc:
    arr = np.ones(c+1, dtype="i8")
    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(len(aa[i])+1, 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