-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.py
More file actions
executable file
·47 lines (31 loc) · 746 Bytes
/
Copy pathsol.py
File metadata and controls
executable file
·47 lines (31 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
CACHE = [0]
def n_ones(n):
return CACHE[n]
def contribution(s, i):
subsequences = i + 1
digit = int(s[i])
if digit == 0:
return 0
else: # 1
if subsequences % 2 == 0:
return 0
else:
return n_ones(len(s) - i)
def solve():
n = int(input())
s = input()
result = -1
for i in range(len(s)):
if result == -1:
result = contribution(s, i)
else:
result = result ^ contribution(s, i)
print(result % 998244353)
def generate_cache():
while len(CACHE) <= 100000:
CACHE.append(CACHE[-1] * 2 + 1)
if __name__ == "__main__":
T = int(input())
generate_cache()
for _ in range(T):
solve()