Submission #38981658
Source Code Expand
t=int(input())
for i in range(t):
n=int(input())
s=input()
f=[]
for j in range(n):
if s[j]=="1":
f.append(j)
if len(f)==2:
if f[0]+1==f[1]:
print(-1 if n==3 else 3 if s=="0110" else 2)
else:
print(1)
elif len(f)%2==0:
print(len(f)//2)
else:
print(-1)
Submission Info
| Submission Time | |
|---|---|
| Task | A - Non-Adjacent Flip |
| User | iwzk |
| Language | Python (3.8.2) |
| Score | 400 |
| Code Size | 318 Byte |
| Status | AC |
| Exec Time | 372 ms |
| Memory | 17284 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt |
| All | 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 16 ms | 8952 KiB |
| 01_test_01.txt | AC | 130 ms | 9040 KiB |
| 01_test_02.txt | AC | 120 ms | 8896 KiB |
| 01_test_03.txt | AC | 372 ms | 8868 KiB |
| 01_test_04.txt | AC | 54 ms | 17284 KiB |
| 01_test_05.txt | AC | 41 ms | 9364 KiB |
| 01_test_06.txt | AC | 48 ms | 12996 KiB |
| 01_test_07.txt | AC | 41 ms | 9092 KiB |