Submission #38971674
Source Code Expand
#include<bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
/*define about others*/
#define ls(k) k<<1
#define rs(k) k<<1|1
#define lson(k) l,mid,ls(k)
#define rson(k) mid+1,r,rs(k)
#define sizea(x,d) x+1,x+d+1
#define all(x) x.begin(),x.end()
#define lowbit(x) (x&-x)
/*define about variable*/
#define re register
#define il inline
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
/*define about pair*/
#define np pair<int,int>
#define tup pair<int,pair<int,int> >
#define mp(a,b) make_pair(a,b)
#define mpp(a,b,c) make_pair(a,make_pair(b,c))
#define fi first
#define se second
#define _1 first
#define _2 second.first
#define _3 second.second
/*define about loop*/
#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define repe(u) for(int i=head[u];i;i=e[i].nxt)
#define repv(i,s) for(int i:s)
/*define about STL*/
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define ump unordered_map
#define pq priority_queue
#define iter iterator
/*define about function*/
#define clz __builtin_clz
#define ctz __builtin_ctz
#define ppc __builtin_popcount
#define clzl __builtin_clzll
#define ctzl __builtin_ctzll
#define ppcl __builtin_popcountll
//#define EXODUS
//#define online_judge
#ifdef online_judge
#define debug(x) 1428
#define Debug(...) 2857
#else
#define debug(x) cerr<<"In Line "<<__LINE__<<' '<<#x<<" = "<<(x)<<'\n'
#define Debug(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace IO{
il int read(){
int ans=0,flag=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flag=-1;ch=getchar();}
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans*flag;
}
il string reads(){
string ans="";char ch=getchar();
while(ch==' '||ch=='\n')ch=getchar();
while(ch!=' '&&ch!='\n')ans+=ch,ch=getchar();
return ans;
}
il char readc(){
char ch=getchar();
while(ch==' '||ch=='\n')ch=getchar();
return ch;
}
il int sqr(int x){return x*x;}
il void reada(int *a,int len){for(int i=1;i<=len;i++)a[i]=read();}
void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
return;
}
}
using IO::read;
bool mem1=0;
int Datas=1,T=1;
int n;char s[2000007];
bool mem2=0;
void Main(){
n=read();scanf("%s",s+1);
int ans=0,flg=0;
for(int i=1;i<=n;i++){
if(s[i]=='1')ans++;
if(s[i-1]=='1'&&s[i]=='1')flg=i;
}
if(ans&1)return puts("-1"),void();
if(ans==2&&flg&&n==3)return puts("-1"),void();
if(ans==2&&flg&&n==4&&flg==3)return puts("3"),void();
if(ans==2&&flg)return puts("2"),void();
printf("%d\n",ans/2);
return;
}
int main(){
#ifdef EXODUS
printf("%.5lfMB\n",abs(&mem2-&mem1)/1024.0/1024.0);
freopen("Data.in","r",stdin);
freopen("Code.out","w",stdout);
#endif
#ifdef online_judge
freopen("input.in","r",stdin);
freopen("user_out.out","w",stdout);
#endif
if(Datas)T=read();
while(T--)Main();
#ifdef EXODUS
cerr<<clock()<<"ms"<<endl;
#endif
return 0;
}
//LOJ loyal users:EXODUS
/*
0. Enough array size? Enough array size? Enough array size? Interger overflow?
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error? Use The TRUE MODULE?
4. Do not forget to CHECK YOUR CODE before submitting!
Delete the DEBUGGING? Add FILE I/O?
*/
Submission Info
Submission Time
2023-02-18 21:17:38+0900
Task
A - Non-Adjacent Flip
User
EXODUS
Language
C++ (GCC 9.2.1)
Score
400
Code Size
3650 Byte
Status
AC
Exec Time
15 ms
Memory
3996 KiB
Compile Error
./Main.cpp: In function ‘void Main()’:
./Main.cpp:98:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
98 | n=read();scanf("%s",s+1);
| ~~~~~^~~~~~~~~~
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
5 ms
3712 KiB
01_test_01.txt
AC
4 ms
3632 KiB
01_test_02.txt
AC
7 ms
3500 KiB
01_test_03.txt
AC
15 ms
3800 KiB
01_test_04.txt
AC
5 ms
3996 KiB
01_test_05.txt
AC
6 ms
3888 KiB
01_test_06.txt
AC
5 ms
3868 KiB
01_test_07.txt
AC
6 ms
3624 KiB