happy to find someone with the same mistake(in these cases many codes failed too). Maybe @taran_1407 sir you should make this as a special note below (or make it bold )because many seem to have done this mistake . it will help them realize their mistake quickly
Thanks for the test case. Really appreciate it.
Whatâs Wrong with my solution
Basically I am checking all the unique transitions from any character to a particular character âŚwe can select all of them + 1 from string 1 which is same as the character we are going to âŚwe will perform from âzâ to 'a â so they donât overlap.
https://www.codechef.com/viewsolution/33515806
I have tried all the cases mentioned in other commentsâŚgot the expected answer.
Whatâs Wrong with my solution
Basically I am checking all the unique transitions from any character to a particular character âŚwe can select all of them + 1 from string 1 which is same as the character we are going to âŚwe will perform from âzâ to 'a â so they donât overlap.
You should read what you actually have to print out in the operations
@praty_u_s_h your code was working ok but you forgot one important thing in the question.
for each move or step you should first output the number of elements in s.
for input :
1
5
bddac
abcab
your ouput was:
3
4 2
0 1 4
3 0
but the correct output is:
3
2 4 2
3 0 1 4
2 3 0
congrats on red
Thanks, itâs my favorite color so I made great efforts to get there
@galencolin Are you till in school? do junior coders have rating increase based on other junior coders? I just wish to know. You still are awesome because everyone gets the same questions
Thereâs a separate âjuniorâ rating for people still in school (which I am). It doesnât affect the main codechef rating in any way.
Where did this code fail
#include <bits/stdc++.h>
#pragma GCC optimize(âOfastâ)
#pragma GCC target(âavx,avx2,fmaâ)
#define ll long long int
#define pii pair<int,int>
#define vi vector
#define umap unordered_map<ll,ll>
#define uset unordered_set
using namespace std;
int main()
{
int t; cin >> t;
while(t--)
{
int n, count = 0, flag = 0; cin >> n;
vector<char> a(n), b(n);
for(auto &x : a) cin >> x;
for(auto &x : b) cin >> x;
if(a==b)
{
cout<<0<<endl;
cout<<n<<" ";
for(int i=0;i<n;i++)
{
cout<<i<<" ";
}
continue;
}
map<char, set<int> > hmap;
map<char,int> amap, bmap;
for(auto x : a) amap[x]++;
for(auto x : b) bmap[x]++;
for(auto x : b)
{
if(amap[x] == 0 && bmap[x] != 0)
{
flag = 1;
break;
}
}
if(flag)
{
cout << -1 << endl;
}
else
{
for(int i=n-1;i>0;i--)
{
if(a[i]!=b[i])
{
hmap[b[i]].insert(i);
for(int j=0;j<i;j++)
{
if(a[j]==b[i])
{
hmap[b[i]].insert(j);
}
}
for(int j=i+1;j<n;j++)
{
if(a[j]==b[i])
{
hmap[b[i]].insert(j);
}
}
a[i]=b[i];
}
else
{
continue;
}
}
cout<<hmap.size()<<endl;
for(auto x : hmap)
{
cout << x.second.size() << " ";
for(auto y : x.second) cout << y << " ";
cout << endl;
}
}
}
return 0;
}
OhhâŚdidnât pay much attention âŚthought there could be multiple answers âŚthanks!..WOw
Thanks!
I got partial points, please tell me whatâs wrong with this with this code.(approach is similar to editorialistâs solution). CodeChef: Practical coding for everyone
THANKS IN ADVANCE.
If I print the answer from z to a it gives AC , but from a to z it gives WA
But mathematically it can be proven that each set has unique elements.
Here is link to my submission
https://www.codechef.com/viewsolution/33503396
If you change the loop from 25 to 0 which is written as (0 to 25) on line number 91 the solution get accepted
Can anyone help to understand why it gives WA for printing solution in ascending order
Can someone help me to figure out why I am getting WA in 1st subtask while getting AC in 2nd? I have checked all test cases, but canât find the error? plz help.
https://www.codechef.com/viewsolution/33486726
There is no ONE FIXED SOLUTION, the main thing is not the S subset, but the minimum number of steps required
We can prove that it is optimal to apply operations in decreasing order of chchch as it doesnât affect candidate positions for **special positions** for subsequent positions.
How to prove this part?
What I have thought yet is after checking both of the conditions of â-1â.
If it is possible to make A to B then,
For all characters from z to a that are present in B, at an instance let the character be ch in B. We are updating all the characters in A that should be equal to ch, but are greater than ch. So, it will never affect our special positions for subsequent positions.
Lets assume that it does affect the subsequent positions then, it means that the character ch has already been replaced in A by any other smaller character. But it is not possible since we are at an instance updating all the characters in A that are greater ch, but should be equal to ch.
Eg.
A = a, c, d, e
B = a, a, c, d
In the string A characters c and d are special positions because they help in updating the other positions and gets updated to some other character as well.
Suppose our ch is d in B, so, if A to B conversion is possible then, d will always be present in A since we have only updated those characters in A which were greater than d. So, if d is not present in A, it means that we have already updated âdâ to âcâ or any other smaller character, which is not possible since we are converting from z to a, so we will convert from d first and then, c.
Therefore, conversion from z to a is optimal and doesnât affect special positions.
i got wa , i can,t figure it out⌠please help me to find
https://www.codechef.com/viewsolution/33518415
wow!!!