Help in finding error in a problem

Revision en4, by ayush29azad, 2021-10-08 08:56:16

Can someone help me in fiding error in my code ?? It is failing on a test case but I am not able to figure it out . Problem Link : https://mirror.codeforces.com/contest/1562/problem/C

My logic :

Case 1 — string contains all 1s then simply print starting and ending indexes of any two substrings of length greater than n/2. as they will be multiple of each other . like 11111111 >>> 1111 and 1111 their decimal values both will be multiple of each other .

Case 2 — if the first zero is finding at length less than or = to n/2 then print the index of a substring starting from there till the end and other excluding that zero and till the end. Like 101111 >>> 01111 and 1111, their decimal values both will be multiple of each other .

Case 3 — if the first zero is at length greater than n/2 then print the index of a substring starting from index 1 till it and the other starting from 1 to l-1. ****

I think it is failing on Case 1 But not able to figure it out why and where Please Help!!!!!



void solve() { ll n;cin>>n;string s;cin>>s; ll l=-1; for(int i=0;i<n;i++) { if(s[i]=='0') { l = i+1; break; } } if(l==-1) { cout<<1<<" "<<n/2<<" "<<n/2+1<<" "<<n<<"\n";return ; } if(l<=n/2) { cout<<l<<" "<<n<<" "<<l+1<<" "<<n<<"\n"; return ; } else { cout<<1<<" "<<l<<" "<<1<<" "<<l-1<<"\n";return ; } }

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English ayush29azad 2021-10-08 08:56:16 6 Tiny change: ' >>> 1111 1111 heir decim' -> ' >>> 1111 and 1111 their decim'
en3 English ayush29azad 2021-10-08 08:54:53 32 Tiny change: ' and other excluding' -> ' and others excluding'
en2 English ayush29azad 2021-10-08 08:53:02 5
en1 English ayush29azad 2021-10-08 08:52:36 1567 Initial revision (published)