You are not logged in. Please login at www.codechef.com to post your questions!

×

CHEFTET July Challenge help

Can Somebody help me about what's wrong with my solution for JULY challenge problem chef and tetris and my approach was to check out 4 possible values so that we can make all array elements equal but I am getting wrong answer for 7th and 12th task

my solution : https://www.codechef.com/viewsolution/10812639

asked 15 Jul '16, 07:54

sau1999's gravatar image

4★sau1999
6524
accept rate: 0%

edited 15 Jul '16, 17:06

dpraveen's gravatar image

4★dpraveen ♦♦
2.5k53137170


@sau1999 I tried running your code on my PC, for this particular input:
1
3
1 2 3
1 2 3
your code gives output:
3
but the correct output should be -1, in your code, I think you're using the array 'vis' to check if elements in 'b' have been used or not i.e vis[i]==0 indicates that the 'i'th element has not been used and vis[i]==-1 indicates that the 'i'th element has been used. I have added this line:
cout << vis[1] << " " << vis[n-1] << " " << c[i] << endl;
just before the inner for loop is closed,I've noticed that vis[n-1] is '0' for all the four iterations, and yet your code gives an output '3', basically you're not checking if the last element in 'b' has been used or not i.e if vis[n-1]==0.

link

answered 15 Jul '16, 14:00

hemanth_1's gravatar image

6★hemanth_1
1.4k12
accept rate: 28%

@hemanth_1 : thanks for giving answer but i think for your given test case answer should be 3 because b = {1,2,3} a = {1,2,3} b[1] will fall on a[0] (2 + 1 = 3) b[0] will fall on a[1] (1 + 2 = 3) and as a[2] is already 3 no element will on a[2] thus vis[n-1] = 0`

(15 Jul '16, 15:00) sau19994★

@sau1999 Where shall b[2] fall?

(15 Jul '16, 15:11) tony_hager5★
2

@sau1999 We have to use all the elements of array b.

(15 Jul '16, 15:17) an26093★

All the elements in 'B' must be used

(15 Jul '16, 18:32) hemanth_16★

thanks for clearing the problem statement I asked this question on the contest but no one replied

(15 Jul '16, 19:02) sau19994★

@vnvipinsingh

This happened with me as well. It is happening because of n=1.

Just a separate if statement for n=1 needs to be added.

my wrong solution

my correct solution

your corrected solution

link

answered 15 Jul '16, 15:52

prakhariitd's gravatar image

6★prakhariitd
1.1k211
accept rate: 10%

can you tell me what is wrong in my solution for chef and tetris. https://www.codechef.com/viewsolution/10824494

@sau1999

my approach is somewhat similar to you. i also try to make all element equal to a[0] or a[0]+b[0] or a[0]+b[1] or a[0]+b[0]+b[1]. i try to go through your code what its hard to get what you are trying to do. one funny thing is that your solution is not passing the 7th and 12th task and my solution is failing on 1st task.

link

answered 15 Jul '16, 13:54

vnvipinsingh's gravatar image

3★vnvipinsingh
213
accept rate: 0%

@hemanth_1 please tell me why my solution is wrong. https://www.codechef.com/viewsolution/10824494

link

answered 15 Jul '16, 14:43

vnvipinsingh's gravatar image

3★vnvipinsingh
213
accept rate: 0%

@prakhariitd thanks

link

answered 15 Jul '16, 16:53

vnvipinsingh's gravatar image

3★vnvipinsingh
213
accept rate: 0%

Please tell me what's wrong with this : https://www.codechef.com/viewsolution/10763381

Thanks in advance.

link

answered 15 Jul '16, 22:20

anujdubey1996's gravatar image

3★anujdubey1996
1
accept rate: 0%

Can anyone please tell me whats wrong in my code
it gives wrong answer on Task #9
--->> https://www.codechef.com/viewsolution/10777387

link

answered 17 Jul '16, 17:03

iamashish's gravatar image

2★iamashish
1
accept rate: 0%

Hey.. in this problem i got stuck in the 10th test case.. can any one tell whats wrong with my approach?? my algo is: if all elements of (a[n]+b[n]) is not divisible by n--> then print -1 else check for all the possible sums for one a[i] { b[i-1]+a[i] , b[i]+a[i] , b[i+1]+a[i] , b[i-1]+b[i]+a[i] , b[i+1]+b[i]+a[i] ,b[i-1]+b[i+1]+a[i] and b[i-1]+b[i]+b[i+1]+a[i]} from these if a[i]+any of these are equal to the desired element that is (a[n]+b[n])/n then making the/those b[i] value/values zero i proceed to check next a[i] element. here is the source code.. https://www.codechef.com/viewsolution/10759208

link

answered 17 Jul '16, 21:25

aj619's gravatar image

3★aj619
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×858
×477
×29

question asked: 15 Jul '16, 07:54

question was seen: 2,503 times

last updated: 17 Jul '16, 21:25