ayush29azad's blog

By ayush29azad, history, 2 years ago, In English

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://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 ; } }
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?