Can someone please figure out where i went wrong.
https://www.codechef.com/viewsolution/33499945
will check it now, thanks!
BRO,can u please little comment yout code…
Your code fails on
abcde , aabaa
Check your output
On this case -
abcde
aabbe
smallest number of operations needed is 2
your code outputs 3
i think this case will give wrong answer.
4
aabc
aaab
check it out.
https://www.codechef.com/viewsolution/33482147
Can someone help me to figure out why I am getting WA in 1st subtask while getting AC in 2nd?
Thanks man, got it.
can anybody tell me on which test case it is failing.
Can’t figure out where my code gives WA for second subtask, could someone help?
Could someone figure out my mistake.
My Idea was to iterate from z to a find positions of the that char in both a and b if differ count increases.If a doesnt contain it return -1.
My solution link https://www.codechef.com/viewsolution/33489863
Can anyone tell me what si wrong with my code, all test case are passed
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int dp[26];
while(t–)
{
memset(dp,-1,sizeof(dp));
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
bool flag=0;
vector<pair<char,int> >v;
for (int j=0;j<n;j++)
dp[s1[j]-‘a’]=j;
for (int j=0;j<n;j++)
{
if (s1[j]!=s2[j])
{
if (s1[j]>s2[j])
{
if (dp[s2[j]-‘a’]!=-1)
{
v.push_back({s2[j],j});
}
else
{
flag=1;
break;
}
}
else
{
flag=1;
break;
}
}
}
if (flag==1)
{
cout<<"-1"<<endl;
continue;
}
else
{
int r=v.size();
vectorv1,result;
for (int j=0;j<r;)
{
vectorans;
char temp=v[j].first;
ans.push_back(dp[v[j].first-‘a’]);
while(j<r&&v[j].first==temp)
{
ans.push_back(v[j].second);
j++;
}
int e=ans.size();
v1.push_back(e);
for (int k=0;k<e;k++)
result.push_back(ans[k]);
}
int e=v1.size();
cout<<e<<endl;
int k=0;
for (int j=0;j<e;j++)
{
cout<<v1[j]<<" “;
int r=k+v1[j];
for (;k<r;k++)
cout<<result[k]<<” ";
cout<<endl;
}
}
}
}
rankings are updated
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.