×

# Need help in Mixcolor

 0 I am trying to solve MIXCOLOR and my code passes all the given test cases also the one's that I am giving it but it is still giving me WA on codechef judge. Please help me in finding the error in my code or my understanding. My code: #include #include using namespace std; int main() { // your code goes here int t; cin>>t; while(t --) { long long int n; cin>>n; long long int a[n]; for(long long int i=0;i>a[i]; } sort(a,a+n); long long int max = a[n-1]; long long int c = 0; for(long long int i=1;i

 2 U need to make changes in a[i-1] not in a[i] and after that u will get write verdict. answered 20 Mar '18, 16:31 293●6 accept rate: 33% 1 https://www.codechef.com/viewsolution/17919387 i have made changes in ur solution u caan view and pls upvote (20 Mar '18, 16:34) 1 And the reason is that a[i] need to be compared to a[i+1] as we need to change all the repeating element; ex 2 2 2 3 by ur code it will change a[1] and it won't be then equal to a[2] which is also 2. (20 Mar '18, 16:40) 1 if we u still face problem ask freely (20 Mar '18, 16:57) Thanks brother.. I just don't get how is that making a big difference.. I was updating a[i] since I thought a[i-1] was already a unique color.. Please correct me if I am wrong.. (20 Mar '18, 17:21) montycs0★ 1 when u sort array u get all those no together which are not unique like 1 2 2 2 3 3 7 7 so if u update a[i] in place of a[i-1] then u r gonna miss which are a[i+1]. we can easily understand it by example as here a[1]==a[2] so if u update a[2] then u will miss a[3] which is also 2(in this case); a[3] and a[1] will remain same. (20 Mar '18, 17:45) 1 if u r still confused then let me tell u another approach to his question this question was never meant to update value it just need us to count the no of repeating element after sorting (like 2 2 2 2 so answer would be 3).and ur code in another way https://www.codechef.com/viewsolution/17919825 (20 Mar '18, 17:54) 1 ur code in another way has also passed all the verdict (20 Mar '18, 17:56) wooah.. thanks brother. (20 Mar '18, 18:01) montycs0★ showing 5 of 8 show all
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,718
×832
×265

question asked: 20 Mar '18, 16:20

question was seen: 129 times

last updated: 20 Mar '18, 18:01