Your code will fail for this test case-
1
6
110100
001011
Your code will fail for this test case-
1
6
110100
001011
Output should be Yes
TEST Case:
011
101
Hint: Read question again
potential test cases
2
7
1110000
0011100
7
0110100
1011000
i think
they may suffice to aid debugging if you are getting wa ,
note the triffle difference b/w the 2 test case ,
Hey Everybody,
Link for my solution
CodeChef: Practical coding for everyone
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?
thanks for looking into this, yes I see I made a stupid mistake.
I created a variable got = 0.
I just iterated from 0 to the length of the string.
Then I checked if (s[i] == '1' and p[i] == '0') got++; else if(s[i] == '0' && p[i] == '1') { if (got >= 1) got--; else { cout << "No\n"; break; } }
and after the loop I printed “Yes\n”.
Though my solution got accepted, I am not sure about the proof.
Can someone explain, please??
can anyone help me figure out where the code is breaking??
void solve()
{
// cout << fixed << setprecision(10);
int n;
string s, p;
cin >> n >> s >> p;
int sOne(0), sZero(0), pOne(0), pZero(0);
rep(i, n)
{
if (s[i] == '1')
sOne++;
else
sZero++;
}
rep(i, n)
{
if (p[i] == '1')
pOne++;
else
pZero++;
}
if (sOne != pOne || sZero != pZero)
{
cout << "No\n";
return;
}
int i(0), j(0);
while (i < n)
{
while (i < n && s[i] == p[i])
{
i++;
}
if (i >= n || s[i] != '1')
{
break;
}
j = i + 1;
while ((j < n && s[j] == p[j]) || (j < n && s[j] == '1'))
{
j++;
}
if (j >= n || s[j] != '0')
{
break;
}
swap(s[i], s[j]);
i = j + 1;
}
if (s == p)
{
cout << "Yes\n";
}
else
{
cout << "No\n";
}
return;
}
take this as testcase
1
2
01
10
here you need to understand you canot swap 0 to 1 because you should choose two indices ii and jj (1≤i<j≤N1≤i<j≤N) such that Si is ‘1’ and Sj is ‘0’, and swap Si with Sj. hope this will help you
your code will give you “YES” but correct answer is “NO”
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.
thanks I got it
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?
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
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
- Find the indices of the misplaced 0s in the s string
- Iterate once over s and if s[i]==p[i] continue
- Else, if s[i] ==‘1’ try to find an index greater than i with misplaced zero, swap elements and remove that index from list
- 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