SWAP10HG - Editorial

My Bruteforce solution got 100 points.
Solution-Click here

Were test cases weak for this problem?

Solution: 40865018 | CodeChef
why it is getting wa?

1 Like

Your code will fail on this test case:

1
3
011
101

Expected output : No
Your Output : Yes

You can’t swap a β€˜0’ with β€˜1’ if 0 is present behind 1.
While
You can swap a β€˜0’ with β€˜1’ if 0 is present after 1.

2 Likes

thanks I got it

1 Like

Hey Everybody,
Link for my solution
Solution: 40830211 | CodeChef
Can anybody help me get why this solution is wrong because this solution got 20 pts initially but after CodeChef removed some test cases the same solution got 70 pts but I am not able to get how this solution is getting WA is some cases?

I got WA. Could you please help me in this :
https://www.codechef.com/viewsolution/40895063

Hi, you are only counting number of 1’s and 0’s in S and P, and comparing them. But the question is β€œCan we convert S into P”, but there is a condition un that conversion also.

You have to convert the string SS into PP using zero or more operations. In one operation, you should choose two indices ii and jj (1≀i<j≀N1≀i<j≀N) such that SiSi is β€˜1’ and SjSj is β€˜0’, and swap SiSi with SjSj

1 Like

https://www.codechef.com/viewsolution/40876472
Can someone give test cases where my code fails?

Would anyone be able to find the error in the following code? It is failing on two tests
submission - CodeChef: Practical coding for everyone

LOGIC

  1. Find the indices of the misplaced 0s in the s string
  2. Iterate once over s and if s[i]==p[i] continue
  3. Else, if s[i] ==β€˜1’ try to find an index greater than i with misplaced zero, swap elements and remove that index from list
  4. And If s[i]==β€˜0’ then we can’t ever change it to 1 as all ones before it must be placed correctly due to step 3, so just break.

why 1st test case is WA what is wrong in this code CodeChef: Practical coding for everyone can any one check it

my solution

I think it’s right, but it shows wrong for all test cases, please help me out here.

hello
bool good = count(all(s), β€˜1’) == count(all(t), β€˜1’);
someone please tell me functionality of all() and what is it that is getting stored in good variable?


//Please tell me in which case my code fails

#include <bits/stdc++.h>
using namespace std;
signed main()
{
	int t;	cin>>t;
	while(t--){
		int n, i, p0=0, p1=0, c0=0, c1=0;
		cin>>n;
		string s, p;
		cin>>s>>p;
		
		for(i=0;i<n;i++){
			if(s[i]=='1') c1++;
			
			if(p[i]=='1') p1++;
		}
		if(c1==p1 && s>=p){
			cout<<"Yes"<<endl;
		}
		else
			cout<<"No"<<endl;
	}
}