結果
問題 | No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ |
ユーザー |
|
提出日時 | 2023-12-09 14:45:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 820 ms / 3,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 82,500 KB |
実行使用メモリ | 80,412 KB |
最終ジャッジ日時 | 2024-09-27 03:35:39 |
合計ジャッジ時間 | 12,983 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
from itertools import combinations from collections import defaultdict from bisect import bisect_left M = int(input()) G = list(map(int, input().split())) H = list(map(int, input().split())) G1 = G[: len(G) // 2] G2 = G[len(G) // 2 :] H1 = H[: len(H) // 2] H2 = H[len(H) // 2 :] H1_Select = [defaultdict(int) for _ in range(15)] H2_Select = [[] for _ in range(15)] for i in range(15): C = list(combinations(range(14), i)) for c in C: tmp = 0 tmp_2 = 0 c_set = set(c) for j in range(14): if j in c_set: tmp += G1[j] tmp_2 += G2[j] else: tmp += H1[j] tmp_2 += H2[j] tmp %= M tmp_2 %= M H1_Select[i][tmp] += 1 H2_Select[i].append(tmp_2) H2_Select[i].sort() Q = int(input()) ans = [] for _ in range(Q): K, X = map(int, input().split()) s = max(0, K - 14) res = 0 for i in range(s, min(K, 14) + 1): A = H1_Select[i] B = H2_Select[K - i] for x, y in A.items(): if x < X: cnt = bisect_left(B, M - x) - bisect_left(B, X - x) else: cnt = bisect_left(B, M - x) + len(B) - bisect_left(B, M + X - x) res += cnt * y ans.append(res) print(*ans, sep="\n")