QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711973 | #6408. Classical Counting Problem | dejian | RE | 0ms | 0kb | Python3 | 1.3kb | 2024-11-05 14:10:50 | 2024-11-05 14:10:51 |
answer
import sys
import math
import threading
def main():
import sys
MOD = 998244353
t = int(sys.stdin.readline())
for _ in range(t):
line = ''
while line.strip() == '':
line = sys.stdin.readline()
n,m,v = map(int,line.strip().split())
a = []
while len(a) < n:
a += list(map(int, sys.stdin.readline().strip().split()))
# For each j, compute C_j = set of i where a_i >= a_j -m
C = []
for j in range(n):
req = a[j] - m
if req <0:
req = -math.inf
Cj = 0
for i in range(n):
if a[i] >= a[j] - m:
Cj |= (1 << i)
C.append(Cj)
# Now, need to count subsets S where for all j not in S, S intersects C_j !=0
# If n >20, it's impossible to iterate. Hence, n<=20
if n >20:
print(0)
continue
total =0
for S in range(1,1<<n):
valid = True
for j in range(n):
if not (S & (1 << j)):
if (S & C[j]) ==0:
valid = False
break
if valid:
total = (total +1)%MOD
print(total%MOD)
threading.Thread(target=main,).start()
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
6 3 1 2 1 2 3 3 2 1 1 2 3 10 1 1 0 0 0 0 0 0 0 0 0 0 6 1 2 2 1 1 3 0 2 6 1 5 2 1 1 3 0 2 10 4 8 7 2 3 6 1 6 5 4 6 5