結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー rlangevinrlangevin
提出日時 2023-12-09 00:16:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,124 ms / 3,000 ms
コード長 986 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 77,900 KB
最終ジャッジ日時 2023-12-09 00:17:14
合計ジャッジ時間 18,306 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
76,292 KB
testcase_01 AC 111 ms
76,868 KB
testcase_02 AC 154 ms
76,860 KB
testcase_03 AC 517 ms
77,256 KB
testcase_04 AC 373 ms
77,224 KB
testcase_05 AC 143 ms
76,620 KB
testcase_06 AC 437 ms
77,000 KB
testcase_07 AC 464 ms
77,504 KB
testcase_08 AC 179 ms
76,280 KB
testcase_09 AC 315 ms
76,500 KB
testcase_10 AC 416 ms
76,452 KB
testcase_11 AC 168 ms
77,128 KB
testcase_12 AC 555 ms
77,312 KB
testcase_13 AC 583 ms
77,128 KB
testcase_14 AC 538 ms
76,592 KB
testcase_15 AC 538 ms
77,000 KB
testcase_16 AC 556 ms
77,900 KB
testcase_17 AC 530 ms
76,860 KB
testcase_18 AC 571 ms
77,088 KB
testcase_19 AC 632 ms
76,976 KB
testcase_20 AC 616 ms
76,872 KB
testcase_21 AC 624 ms
77,348 KB
testcase_22 AC 1,124 ms
76,872 KB
testcase_23 AC 1,101 ms
76,620 KB
testcase_24 AC 1,124 ms
77,384 KB
testcase_25 AC 1,111 ms
77,120 KB
testcase_26 AC 1,109 ms
76,852 KB
testcase_27 AC 57 ms
66,340 KB
testcase_28 AC 83 ms
76,580 KB
testcase_29 AC 1,080 ms
77,384 KB
testcase_30 AC 526 ms
77,200 KB
testcase_31 AC 573 ms
76,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *

M = int(input())
G = list(map(int, input().split()))
H = list(map(int, input().split()))
G1, H1 = G[:14], H[:14]
G2, H2 = G[14:], H[14:]
D1, D2 = [[] for i in range(15)], [[] for i in range(15)]
for s in range(1 << 14):
    v1, v2 = 0, 0
    cnt = 0
    for i in range(14):
        if (s >> i) & 1:
            v1 += G1[i]
            v2 += G2[i]
            cnt += 1
        else:
            v1 += H1[i]
            v2 += H2[i]
    D1[cnt].append(v1%M)
    D2[cnt].append(v2%M)
    
for i in range(15):
    D1[i].sort()
    D2[i].sort()
    
Q = int(input())
for _ in range(Q):
    K, X = map(int, input().split())
    ans = 0
    for i in range(15):
        if K - i < 0 or K - i > 14:
            continue
        for d in D1[i]:
            ind1 = bisect_left(D2[K-i], X - d)
            ind2 = bisect_right(D2[K-i], M - d - 1)
            ind3 = bisect_left(D2[K-i], X + M - d)
            ans += ind2 - ind1 + len(D2[K-i]) - ind3
            
    print(ans)
0