Your code fails on this test -
acebf
aabbe
Try this test case:
3
5
defgb
bbebb
5
defgb
bbbeb
5
defgb
bbbfb
Your code outputs -1 for each task. But it is possible to covert the string.
Anyone having doubt can take a look at my code and dry run against theirs to find the mistake. I have added comments for better readability. Solution.
explain it your code is messed up boi
you have to start with the largest character also code is very messed up and hard to understand at some places try to write clean and easy code it will be good also next time post the link of your submission instead of the code itself!! GOOD LUCK :D!!
Sir, we have to view which solution here. I’m new here, is the main solution to be uploaded later?
Can anyone please tell about the mistake in my solution? I am sure that it will get TLE but it is getting WA too. Were Ais to be written in ascending order only?
https://www.codechef.com/viewsolution/33510740
omg I had correct solution, just had to loop from ‘z’ to ‘a’ instead of ‘a’ to ‘z’. Nice editorial, thanks a lot.
I implemented the solution as Tester’s but don’t know after thinking of going from z to a, I traversed from a to z . . . damn . . . welcome back 3*
plz give the link of the submission
shit happens
void solve(string &s1,string &s2,lli n){
if(s1==s2){
cout<<0<<endl;
return;
}
vector<vector<lli>>ans;
for(char ch='z';ch>='a';ch--){
lli flag1=0;
lli flag2=0;
vector<lli> ind;
loop(i,n){
if(s1[i] > ch and s2[i]==ch){
ind.pb(i);
flag1=1;
}
if(s1[i]==ch and flag2==0){
flag2=1;
ind.pb(i);
}
}
if(flag1 and flag2){
for(auto xt : ind )
s1[xt] = ch;
ans.pb(ind);
}
}
if(s1!=s2)
{
cout<<-1<<endl;
return;
}
else
{
cout<<sz(ans)<<endl;
for(auto xt : ans){
cout<<sz(xt)<<" ";
for(auto xr : xt)
cout<<xr<<" ";
cout<<endl;
}
return;
}
}
O(N*(26)) solution : CodeChef: Practical coding for everyone
I used that only, only once I used ascii. I have to do a lot of practice, this was only my 2nd contest after cook-off. I hope by practice, I can shorten my code. Which corner cases are you telling about?
sorry that test case was wrong!!
upd:- I m trying to understand it, plz wait and it will be helpful if u can tell the logic behind it. thank you
First case where it fails is abc and aaa minimum operation required is 1 whereas your code outputs 2.(Simply select 0,1,2 and it will convert 1st string to aaa in one operation).
Another case is abc aab .Here the minimum operation is correct but the order is different .
Your code in first operation selects 0 and 1 which will make 1st string aac and in second operation your code selects 1 and 2 which means it will make it aaa which is not equal to aab.
so changing the order will make it correct i.e select 1 and 2 first(it will make abb) and then 0 and 1.(it will make aab which is equal to 2nd string).Hope that helps
Can somebody help me to find whats wrong with my solution.
My solution-CodeChef: Practical coding for everyone
Bro ur solution is too lengthy …and many if else 
1
5
abcdd
aabcd