Submission #65900164
Source Code Expand
Copy
mod=998244353for _ in range(int(input())):n,k=map(int,input().split())binomal=list(map(int,bin(n)[2:]))dp_cnt=[[0,0]for _ in range(k+1)]dp_sum=[[0,0] for _ in range(k+1)]dp_cnt[0][1]=1for bit in binomal:ndp_cnt=[[0,0]for _ in range(k+1)]ndp_sum=[[0,0]for _ in range(k+1)]for c in range(k+1):for now in range(2):cnt=dp_cnt[c][now]s=dp_sum[c][now]if not cnt:continuefor d in range(2):if now and d>bit:continuent=now and d==bitnc=c+dif nc>k:continue
mod=998244353
for _ in range(int(input())):
n,k=map(int,input().split())
binomal=list(map(int,bin(n)[2:]))
dp_cnt=[[0,0]for _ in range(k+1)]
dp_sum=[[0,0] for _ in range(k+1)]
dp_cnt[0][1]=1
for bit in binomal:
ndp_cnt=[[0,0]for _ in range(k+1)]
ndp_sum=[[0,0]for _ in range(k+1)]
for c in range(k+1):
for now in range(2):
cnt=dp_cnt[c][now]
s=dp_sum[c][now]
if not cnt:continue
for d in range(2):
if now and d>bit:continue
nt=now and d==bit
nc=c+d
if nc>k:continue
ndp_cnt[nc][nt]+=cnt
ndp_cnt[nc][nt]%=mod
ndp_sum[nc][nt]+=s*2+d*cnt
ndp_sum[nc][nt]%=mod
dp_cnt,dp_sum=ndp_cnt,ndp_sum
print((dp_sum[k][0]+dp_sum[k][1])%mod)
Submission Info
| Submission Time | |
|---|---|
| Task | E - Popcount Sum 3 |
| User | juten |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 450 |
| Code Size | 947 Byte |
| Status | AC |
| Exec Time | 105 ms |
| Memory | 83840 KB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt |
| All | example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 60 ms | 81528 KB |
| hand_00.txt | AC | 103 ms | 83572 KB |
| hand_01.txt | AC | 65 ms | 81648 KB |
| hand_02.txt | AC | 72 ms | 81992 KB |
| random_00.txt | AC | 105 ms | 83316 KB |
| random_01.txt | AC | 104 ms | 83840 KB |
| random_02.txt | AC | 104 ms | 83360 KB |
| random_03.txt | AC | 103 ms | 83468 KB |
| random_04.txt | AC | 104 ms | 83604 KB |
| random_05.txt | AC | 98 ms | 83440 KB |
| random_06.txt | AC | 97 ms | 83136 KB |
| random_07.txt | AC | 99 ms | 83448 KB |
| random_08.txt | AC | 94 ms | 83192 KB |
| random_09.txt | AC | 88 ms | 83204 KB |
| random_10.txt | AC | 96 ms | 83488 KB |
| random_11.txt | AC | 89 ms | 83228 KB |
| random_12.txt | AC | 94 ms | 83556 KB |
| random_13.txt | AC | 93 ms | 83348 KB |
| random_14.txt | AC | 98 ms | 83516 KB |
| random_15.txt | AC | 98 ms | 83464 KB |
| random_16.txt | AC | 95 ms | 83732 KB |
| random_17.txt | AC | 96 ms | 83292 KB |
| random_18.txt | AC | 89 ms | 82988 KB |
| random_19.txt | AC | 90 ms | 83316 KB |
| random_20.txt | AC | 94 ms | 83396 KB |
| random_21.txt | AC | 88 ms | 83300 KB |
| random_22.txt | AC | 96 ms | 83668 KB |
| random_23.txt | AC | 94 ms | 83388 KB |
| random_24.txt | AC | 87 ms | 83588 KB |
| random_25.txt | AC | 93 ms | 83232 KB |
| random_26.txt | AC | 96 ms | 83740 KB |
| random_27.txt | AC | 89 ms | 83288 KB |
| random_28.txt | AC | 95 ms | 83396 KB |
| random_29.txt | AC | 96 ms | 83344 KB |