QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#711973#6408. Classical Counting ProblemdejianRE 0ms0kbPython31.3kb2024-11-05 14:10:502024-11-05 14:10:51

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 14:10:51]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-05 14:10:50]
  • 提交

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

output:


result: