結果

問題 No.2561 みんな大好きmod 998
ユーザー nikoro256nikoro256
提出日時 2023-12-08 14:12:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 949 ms / 4,000 ms
コード長 1,121 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 78,264 KB
最終ジャッジ日時 2023-12-08 14:12:47
合計ジャッジ時間 10,950 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
68,484 KB
testcase_01 AC 93 ms
76,624 KB
testcase_02 AC 59 ms
64,296 KB
testcase_03 AC 264 ms
76,744 KB
testcase_04 AC 251 ms
76,744 KB
testcase_05 AC 248 ms
76,744 KB
testcase_06 AC 655 ms
77,512 KB
testcase_07 AC 69 ms
73,080 KB
testcase_08 AC 51 ms
64,300 KB
testcase_09 AC 83 ms
76,544 KB
testcase_10 AC 51 ms
64,312 KB
testcase_11 AC 283 ms
77,452 KB
testcase_12 AC 50 ms
64,324 KB
testcase_13 AC 66 ms
73,292 KB
testcase_14 AC 64 ms
72,748 KB
testcase_15 AC 949 ms
78,152 KB
testcase_16 AC 69 ms
72,712 KB
testcase_17 AC 51 ms
64,320 KB
testcase_18 AC 73 ms
73,340 KB
testcase_19 AC 686 ms
78,264 KB
testcase_20 AC 80 ms
76,368 KB
testcase_21 AC 50 ms
64,296 KB
testcase_22 AC 50 ms
64,332 KB
testcase_23 AC 82 ms
76,412 KB
testcase_24 AC 50 ms
64,320 KB
testcase_25 AC 51 ms
64,304 KB
testcase_26 AC 404 ms
77,396 KB
testcase_27 AC 348 ms
77,264 KB
testcase_28 AC 198 ms
77,028 KB
testcase_29 AC 123 ms
76,960 KB
testcase_30 AC 161 ms
76,724 KB
testcase_31 AC 256 ms
76,896 KB
testcase_32 AC 198 ms
76,632 KB
testcase_33 AC 128 ms
76,596 KB
testcase_34 AC 346 ms
77,264 KB
testcase_35 AC 158 ms
76,644 KB
testcase_36 AC 163 ms
76,644 KB
testcase_37 AC 131 ms
76,972 KB
testcase_38 AC 166 ms
76,940 KB
testcase_39 AC 189 ms
76,760 KB
testcase_40 AC 193 ms
76,764 KB
testcase_41 AC 172 ms
76,940 KB
testcase_42 AC 222 ms
76,896 KB
testcase_43 AC 131 ms
76,600 KB
testcase_44 AC 161 ms
76,900 KB
testcase_45 AC 261 ms
77,012 KB
testcase_46 AC 217 ms
76,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
A=list(map(int,input().split()))
left=A[:N//2]
right=A[N//2:]
p=998244353
ps=998
exp2=[2**i for i in range(len(A)+1)]

def half(lis):
    lists=[[[] for _ in range(998)] for _ in range(K+1)]
    for i in range(exp2[len(lis)]):
        ans_long=0
        ans_short=0
        count=0
        for j in range(len(lis)):
            if i&1:
                count+=1
                ans_long+=lis[j]
                ans_long%=p
                ans_short+=lis[j]
                ans_short%=ps
            i>>=1
        if K<count:
            continue
        lists[count][ans_short].append(ans_long)
    for i in range(K+1):
        for j in range(998):
            lists[i][j].sort()
    return lists

import bisect
lefts=half(left)
rights=half(right)
ans=0
for i in range(K+1):
    for j in range(998):
        for t in lefts[i][j]:
            for k in range(998):
                lim=(j+k)%ps
                ans+=bisect.bisect_right(rights[K-i][k],lim-t)
                ans+=bisect.bisect_right(rights[K-i][k],lim-t+p)-bisect.bisect_left(rights[K-i][k],p-t)
                ans%=ps
print(ans)
0