Submission #63100708
Source Code Expand
p = 998244353
N = int(input())
S = input()
A = []
for i in range(N):
if S[i] == "1": A.append(i)
M = len(A)
pow2 = [1]
for i in range(2*N+10):
pow2.append(pow2[-1]*2%p)
if M == 0:
print((pow2[N]-1)%p)
elif M == 1:
print((pow2[N+1]-2)%p)
else:
ans = -2
for t in range(2):
DP = [0,0]
DP[t] += 1
A.append(N+A[0])
for i in range(M):
newDP = [0,0]
newDP[0] += DP[0] * pow2[A[i+1]-A[i]]
newDP[1] += DP[0] * (pow2[A[i+1]-A[i]] - 1)
newDP[0] += DP[1] * pow2[A[i+1]-A[i]]
newDP[1] += DP[1] * pow2[A[i+1]-A[i]]
DP = [newDP[0]%p, newDP[1]%p]
ans += DP[t]
print(ans%p)
Submission Info
| Submission Time | |
|---|---|
| Task | B - Broken Wheel |
| User | Quez9271 |
| Language | Python (PyPy 3.10-v7.3.12) |
| Score | 800 |
| Code Size | 676 Byte |
| Status | AC |
| Exec Time | 208 ms |
| Memory | 298776 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 800 / 800 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 55 ms | 76324 KiB |
| 001.txt | AC | 54 ms | 76448 KiB |
| 002.txt | AC | 130 ms | 222292 KiB |
| 003.txt | AC | 91 ms | 131028 KiB |
| 004.txt | AC | 119 ms | 176384 KiB |
| 005.txt | AC | 158 ms | 242104 KiB |
| 006.txt | AC | 93 ms | 126896 KiB |
| 007.txt | AC | 112 ms | 156424 KiB |
| 008.txt | AC | 168 ms | 244992 KiB |
| 009.txt | AC | 131 ms | 185376 KiB |
| 010.txt | AC | 121 ms | 168972 KiB |
| 011.txt | AC | 168 ms | 245932 KiB |
| 012.txt | AC | 178 ms | 265792 KiB |
| 013.txt | AC | 137 ms | 239064 KiB |
| 014.txt | AC | 161 ms | 253292 KiB |
| 015.txt | AC | 177 ms | 268540 KiB |
| 016.txt | AC | 186 ms | 281272 KiB |
| 017.txt | AC | 197 ms | 298684 KiB |
| 018.txt | AC | 208 ms | 298776 KiB |
| 019.txt | AC | 179 ms | 276484 KiB |
| 020.txt | AC | 179 ms | 276656 KiB |
| 021.txt | AC | 138 ms | 238844 KiB |
| example0.txt | AC | 55 ms | 76640 KiB |
| example1.txt | AC | 54 ms | 76324 KiB |