結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー 👑 rin204rin204
提出日時 2023-12-09 13:07:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 302 ms / 3,000 ms
コード長 1,065 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 85,692 KB
最終ジャッジ日時 2023-12-09 13:07:46
合計ジャッジ時間 9,322 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
85,052 KB
testcase_01 AC 167 ms
84,924 KB
testcase_02 AC 203 ms
85,564 KB
testcase_03 AC 238 ms
85,564 KB
testcase_04 AC 212 ms
85,564 KB
testcase_05 AC 186 ms
85,436 KB
testcase_06 AC 225 ms
85,564 KB
testcase_07 AC 222 ms
85,564 KB
testcase_08 AC 217 ms
85,692 KB
testcase_09 AC 208 ms
85,436 KB
testcase_10 AC 224 ms
85,564 KB
testcase_11 AC 210 ms
85,564 KB
testcase_12 AC 236 ms
85,564 KB
testcase_13 AC 258 ms
85,564 KB
testcase_14 AC 229 ms
85,564 KB
testcase_15 AC 233 ms
85,564 KB
testcase_16 AC 231 ms
85,564 KB
testcase_17 AC 230 ms
85,564 KB
testcase_18 AC 267 ms
85,564 KB
testcase_19 AC 238 ms
85,564 KB
testcase_20 AC 234 ms
85,564 KB
testcase_21 AC 242 ms
85,564 KB
testcase_22 AC 300 ms
85,436 KB
testcase_23 AC 275 ms
85,436 KB
testcase_24 AC 272 ms
85,564 KB
testcase_25 AC 268 ms
85,564 KB
testcase_26 AC 302 ms
85,564 KB
testcase_27 AC 161 ms
84,924 KB
testcase_28 AC 171 ms
84,924 KB
testcase_29 AC 275 ms
85,564 KB
testcase_30 AC 192 ms
84,924 KB
testcase_31 AC 234 ms
85,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

M = int(input())
n = 28
G = list(map(int, input().split()))
H = list(map(int, input().split()))

l = 18
L = [[] for _ in range(l + 1)]
for bit in range(1 << l):
    pc = 0
    tot = 0
    for i in range(l):
        if bit >> i & 1:
            pc += 1
            tot += G[i]
        else:
            tot += H[i]
    L[pc].append(tot % M)

for i in range(l + 1):
    L[i].sort()

R = []
for bit in range(1 << (n - l)):
    pc = 0
    tot = 0
    for i in range(n - l):
        if bit >> i & 1:
            pc += 1
            tot += G[i + l]
        else:
            tot += H[i + l]
    R.append((pc, tot % M))

Q = int(input())
for _ in range(Q):
    k, x = map(int, input().split())
    ans = 0
    for kk, vv in R:
        t = k - kk
        if t < 0 or l < t:
            continue
        low = (x - vv) % M
        upp = M - vv
        if low < upp:
            ans += bisect_left(L[t], upp) - bisect_left(L[t], low)
        else:
            ans += bisect_left(L[t], upp) + len(L[t]) - bisect_left(L[t], low)

    print(ans)
0