Submission #40139243
Source Code Expand
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒▒▒▒▒▒▒▒▒▒▒▀██████▄
░███▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
string s;
cin >> s;
int on=0;
for(char i:s)
if(i=='1')
on++;
if(on%2==1)
cout << -1 << endl;
else if(on==0)
cout << 0 << endl;
else if(on>3)
cout << on/2 << endl;
else
{
bool sign=false;
for (int i = 0; i < s.size()-1; ++i)
if(s[i]=='1' and s[i+1]=='1')
sign=true;
if(sign==false)
cout << 1 << endl;
else
{
if(s.size()==2 or s.size()==3)
cout << -1 << endl;
else
{
if(s.size()==4 and s[0]=='0' and s[3]=='0')
cout << -1 << endl;
else
cout << 2 << endl;
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Non-Adjacent Flip |
| User | Muhammad_Daniyal |
| Language | C++ (GCC 9.2.1) |
| Score | 0 |
| Code Size | 1934 Byte |
| Status | WA |
| Exec Time | 116 ms |
| Memory | 3700 KiB |
Compile Error
./Main.cpp: In function ‘void solve()’:
./Main.cpp:39:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
39 | for (int i = 0; i < s.size()-1; ++i)
| ~~^~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 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 | 7 ms | 3572 KiB |
| 01_test_01.txt | WA | 40 ms | 3556 KiB |
| 01_test_02.txt | WA | 37 ms | 3540 KiB |
| 01_test_03.txt | AC | 116 ms | 3576 KiB |
| 01_test_04.txt | AC | 4 ms | 3700 KiB |
| 01_test_05.txt | AC | 4 ms | 3700 KiB |
| 01_test_06.txt | AC | 3 ms | 3548 KiB |
| 01_test_07.txt | AC | 4 ms | 3488 KiB |