QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#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()
Details
Tip: Click on the bar to expand more detailed information
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