CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » Array Transform

Array Transform

Problem code: ARRAYTRM

  • Submit
  • All Submissions

Given n numbers, you can perform the following operation any number of times : Choose any subset of the numbers, none of which are 0. Decrement the numbers in the subset by 1, and increment the numbers not in the subset by K.

Is it possible to perform operations such that all numbers except one of them become 0 ?

Input :

The first line contains the number of test cases T. 2*T lines follow, 2 for each case. The first line of a test case contains the numbers n and K. The next line contains n numbers, a_1...a_n.

Output :

Output T lines, one corresponding to each test case. For a test case, output "YES" if there is a sequence of operations as described, and "NO" otherwise.

Sample Input :
3
2 1
10 10
3 2
1 2 2
3 2
1 2 3

Sample Output :
YES
YES
NO

Constraints :
1 <= T <= 1000
2 <= n <= 100
1 <= K <= 10
0 <= a_i <= 1000

Date: 2010-04-09
Time limit: 2s
Source limit: 50000
Languages: C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK JS


  • Submit

Comments

  • Login or Register to post a comment.

can  anyone put some more

nee87 @ 15 Aug 2010 12:57 AM

can  anyone put some more sample input and output cases of this problem

what should be the out output

gunesaurabh @ 6 Sep 2010 09:04 AM

what should be the out output for following test case?

3 2

0 0 1

 

It is "YES" initially. But if we do a single operation, it will become "NO". So is "YES" possible with initial set without doing operation?

 

Thanks,

Saurabh

"Any number of times"

triplem @ 6 Sep 2010 10:03 AM

"Any number of times" includes 0 times.

@admin, can you please give

kushal154 @ 27 Sep 2010 08:46 PM

@admin, can you please give me a test case where solution is failing. I think my logic is correct.

An extra test case would make

triplem @ 29 Sep 2010 06:40 AM

An extra test case would make things too easy. Your logic is not correct; check it thoroughly and you should be able to come up with a test case yourself.

@Stephen, got it. Just one

kushal154 @ 29 Sep 2010 11:14 AM

@Stephen, got it. Just one silly mistake. Thanks.

@admin can you tell me a test

anurag_aggarwal @ 26 Oct 2010 08:13 PM

@admin

can you tell me a test case where my solution is falling i think my logic is correct

12 32 1 That should be 'YES';

triplem @ 27 Oct 2010 10:12 AM

1
2 3
2 1

That should be 'YES'; choose everything as the subset and you immediately are done.

i didnt considered this case

anurag_aggarwal @ 27 Oct 2010 04:44 PM

i didnt considered this case ...

when k can be greater than n...

 

thanks Stephen...

wasn't reading the problem

anurag_aggarwal @ 27 Oct 2010 05:47 PM

wasn't reading the problem statement correctly...

but still stuck at same point.....

can anyone look at it....

http://www.codechef.com/viewsolution/365982

I'm afraid you're still

triplem @ 28 Oct 2010 03:47 AM

I'm afraid you're still giving the wrong answer most of the time. For example:

1
3 1
2 3 4

Correct answer is YES. There are other types of input which you are also getting wrong, but since coming up with these test cases is half the work of solving the problem, I won't be giving you any more ;)

thans Stephen   I think I am

anurag_aggarwal @ 28 Oct 2010 07:30 PM

thans Stephen

 

I think I am unable to come up with test cases that is why I am unable to solve many problems of the coechef despite  kowing on algorithm....

i will try it...

@stephen all the test cases

gauravsc @ 17 Dec 2010 07:34 PM

@stephen all the test cases you have told above , My code works for all of them ? but I am still getting wrong answer :( Can you please throw some light :-/

@admin how could this case 13

abeyy @ 17 Dec 2010 09:39 PM

@admin

how could this case

1
3 1
2 3 4

be yes...?

Choose the second and third

triplem @ 18 Dec 2010 02:02 AM

Choose the second and third numbers:

3 2 3

Choose the first and third numbers three times:

0 5 0

Somebody Plz look at this

coolnaveen90 @ 19 Dec 2010 04:29 PM

Somebody Plz look at this solution also. ...

http://www.codechef.com/viewsolution/402392

Sorry, plz look this soln.

coolnaveen90 @ 19 Dec 2010 04:53 PM

Sorry, plz look this soln. and ignore the previous post ...

http://www.codechef.com/viewsolution/402406

@Stephen: My solution works

patelatharva @ 27 Dec 2010 12:40 PM

@Stephen:

My solution works for all test cases including those in the comments but while submitting I get a run time error.

Faqs says that it may be due to memory overhead.

But I have only used dynamic memory allocations as required by the values of n in the problem statement.

The code works completely fine on my machine

So what should be the problem ?!

Should I try long static arrays instead of small Dynamic arrays ?!

 

 

That's only one possibility

triplem @ 27 Dec 2010 01:18 PM

That's only one possibility for runtime error.. another one it mentions is that a main function must always return 0.

OK I got my error it was

patelatharva @ 27 Dec 2010 01:44 PM
OK I got my error it was NZEC. Meaning return 0 was missing !! :S

guys it will really kind of

abhinavatul @ 31 Dec 2010 08:16 AM

guys it will really kind of you if you could take a look at http://discuss.codechef.com/showthread.php?p=3667#post3667 , why am i getting wrong answer even though I have a mathematical proof of my logic , it works for all above test cases including those mentioned in comments

can some one please check my

mendax @ 20 Jan 2011 06:07 PM

can some one please check my submission ....?http://www.codechef.com/viewsolution/427187.... i did the same thing which abhinav atul mentioned in the post http://discuss.codechef.com/showthread.php?p=3667#post3667....please help me..   :)

can some one please check my

mendax @ 20 Jan 2011 06:09 PM

can some one please check my submission ....? http://www.codechef.com/viewsolution/427187 .... i did the same thing which abhinav atul mentioned in the post http://discuss.codechef.com/showthread.php?p=3667#post3667....please help me..   :)

@admin: Can you give me a

bipasaforu @ 22 Jan 2011 03:59 PM

@admin:

Can you give me a test case where my solution is giving the wrong answer? 

is this logic correct that if

iiit @ 22 Jan 2011 04:30 PM

is this logic correct that if i can find any subset of n-1 numbers such that all get converted into a number x after some operations then the ans is yes

pls respond as soon as possible

thank you

alas got AC

iiit @ 22 Jan 2011 11:14 PM

alas got AC

@admin I've tried all the

parighagupta @ 23 Jan 2011 11:23 AM

@admin

I've tried all the test cases u said above and the answer is right. Still its saying 'wrong answer'... can u tell me a test case where my solution fails?

my id is 428976

parighagupta @ 23 Jan 2011 11:57 AM

my id is 428976

@parigha i guess u hav

iiit @ 23 Jan 2011 01:10 PM

@parigha

i guess u hav followed the approach given by abhinav which is wrong

if u hav then respond so that i can tell the mistake in that approach

@garima i haven't fully used

parighagupta @ 23 Jan 2011 10:36 PM

@garima

i haven't fully used abhinav's algorithm... just till d mathematical part (i.e. till finding the remainders)... is something wrong till there?

@parigha there is a mistake

iiit @ 24 Jan 2011 12:05 PM

@parigha

there is a mistake in it

as given in the forum m%(k+1)=a_i%(k+1)

from here we conclude that n-1 numbers must hav same remainder and the left one can hav same or different rem

so we conclude there should be 1 or 2 distinct remainders

if there are 1 or 2 distinct rem we say yes but it has a mistake, consider only n-2 numbres out of n can be made 0 at at time and all of them giv same rem say x the rest of the two numbers can giv x or something else as rem if they also giv x

we get 1 distinct rem and we output yes which is wrong

@Parigha I'm not sure what

triplem @ 24 Jan 2011 02:42 PM

@Parigha

I'm not sure what garima is talking about, but your issue occurs when the first three elements of c are all the same.

are a_i s always

architgupta @ 25 Jan 2011 05:03 PM

are a_i s always positive

initiallly as well as during the transformation

The initial constraints are

triplem @ 26 Jan 2011 09:57 AM

The initial constraints are mentioned in the problem. It doesn't say anywhere they can't become negative at any point.

I am facing some trouble

Gaurav Jain @ 28 Jan 2011 11:25 PM

I am facing some trouble understanding the problem.. Can someone explain why the answer is NO for the following sample case:

3 2

1 2 3

Sorry.. I did not read the

Gaurav Jain @ 28 Jan 2011 11:31 PM

Sorry.. I did not read the problem statement carefully.. Ignore my above comment!

could anyone help me

vi269 @ 29 Jan 2011 06:40 PM

could anyone help me pleasehttp://www.codechef.com/viewsolution/437720

@admin what will be answer

mayank_gupta @ 30 Jan 2011 12:27 AM

@admin

what will be answer for these sequences:

1. 3 4 6 9 11 12 15

2. 4 6 9 11 14 17

3. 4 6 9 11 12 15

4. 3 6 9 11 12 15

5. 3 6 9 10 11 15

Pls. give me the answers..

In which language I should

mayank_gupta @ 30 Jan 2011 12:52 AM

In which language I should submit the program:

C(gcc-4,3,2), C99 strict(gcc 4.3.2), C++(gcc-4.0.0-8) or C++(gcc-4.3.2)

 

I dont know why it is giving answer to both of my solutions:

1. http://www.codechef.com/viewsolution/438058

2. http://www.codechef.com/viewsolution/438041

To admin @above comment.. it

mayank_gupta @ 30 Jan 2011 12:53 AM

To admin

@above comment..

it is giving wrong answer after submitting the solution

@Mayank : At codechef you

manoharsingh23 @ 30 Jan 2011 03:00 PM

@Mayank : At codechef you dont have to print messages to ask for input in your soln . You should assume that Judge knows when to input what values and in what format.

to admin, could you please

esha_c @ 30 Jan 2011 03:09 PM

to admin,

could you please tell me at what case my solution is giving a wrong answer, as it is running fine on m machine

http://www.codechef.com/viewsolution/438389

also should an input all zeroes generate yes or no?

@Admin Getting a wrong answer

pilania @ 30 Jan 2011 04:43 PM

@Admin

Getting a wrong answer for this solution http://www.codechef.com/viewsolution/438432

All the test cases are working fine.

to admin, could you please

ankitagarwal98 @ 30 Jan 2011 05:10 PM

to admin,

could you please tell me at what case my solution is giving a wrong answer, as it is running fine on my machine

http://www.codechef.com/viewsolution/438478

@Manmohar: Thanks for the

mayank_gupta @ 30 Jan 2011 05:21 PM

@Manmohar: Thanks for the suggestion. So after removing that line will my code work correctly??

@admin Please tell why my

ankitagarwal98 @ 30 Jan 2011 05:36 PM

@admin

Please tell why my code is showing wrong output? even when all test cases are working.

http://www.codechef.com/viewsolution/438495

@admin please tell why my

rocker.da @ 31 Jan 2011 04:12 PM

@admin

please tell why my solution failing? I have consider all test cases including in comments section.

@admin   what's wrong in my

prattsishunk @ 4 Feb 2011 01:52 AM

@admin

 

what's wrong in my code?

why am I getting Wrong Answer Error?

 

http://www.codechef.com/viewsolution/443565

@admin what is the answer of

rahuldutta @ 5 Feb 2011 01:15 PM

@admin

what is the answer of this?

2 0

0 0

@admin- could you tell me for

vinayk24 @ 8 Feb 2011 04:33 PM

@admin- could you tell me for what input my code fails?

@Rahul: K>=1

newuser @ 19 Feb 2011 09:06 PM

@Rahul: K>=1

@Sami: For the example you

newuser @ 20 Feb 2011 11:39 AM

@Sami: For the example you provided, the algorithm gives correct answer..

Please can you provide some test case..

Where's my code failing,

newuser @ 20 Feb 2011 11:51 AM

Where's my code failing, please somebody help...

@Admin: I have two doubts:

vishal_dhiman @ 15 Mar 2011 03:48 AM

@Admin: I have two doubts: Very important I think should be added to problem statement to make it clearer.

1. exactly one should be left not equal to zero or all may become zero. (i guess exactly one)

2. A subset as per definition can have all elements and also no element of set, is this the same for this problem also?

@admin : please reply admin.

vishal_dhiman @ 15 Mar 2011 06:35 PM

@admin : please reply admin.

please reply...

vishal_dhiman @ 16 Mar 2011 01:40 AM

please reply...

@Stephen Merriman :Please

vishal_dhiman @ 18 Mar 2011 08:17 PM

@Stephen Merriman :Please reply......

I have two doubts: Very important I think should be added to problem statement to make it clearer.

1. exactly one should be left not equal to zero or all may become zero. (i guess exactly one)

2. A subset as per definition can have all elements and also no element of set, is this the same for this problem also?

@Stephen Merriman :Please

vishal_dhiman @ 18 Mar 2011 08:17 PM

@Stephen Merriman :Please reply......

I have two doubts: Very important I think should be added to problem statement to make it clearer.

1. exactly one should be left not equal to zero or all may become zero. (i guess exactly one)

2. A subset as per definition can have all elements and also no element of set, is this the same for this problem also?

Ohh it was so easy i cant

vishal_dhiman @ 19 Mar 2011 02:03 AM

Ohh it was so easy i cant believe... :P

and answers that i got to my above comment..

1. all can be zero also

2. it can have all elements and also no need of no element case in subset...

can som1 please mail me the

jatingulati25 @ 20 May 2011 03:23 PM
can som1 please mail me the algo for this prob @jatin.gulati25@gmail.com fed up of Compilation error !!

I am getting wrong answer in

arnab_das @ 26 Jun 2011 07:45 PM
I am getting wrong answer in spite all test cases mentioned here are giving correct results. Please help!! Here's my solution: http://www.codechef.com/viewsolution/583793

hi

kittu638 @ 10 Aug 2011 04:55 PM
hi

i am getting wrong answer

khush @ 14 Aug 2011 08:36 PM
i am getting wrong answer inspite of getting correct results of all the test cases even those mentioned in comments ...can some one help me ....please provide some very good test case which helps me to check whether my solution is correct or not.....please help me

admin plz check my soln

amnsinghl @ 31 Aug 2011 09:11 PM
admin plz check my soln getting wrong answer again and again http://www.codechef.com/viewsolution/640630

wrong testcases!!!!!

pikku @ 27 Sep 2011 12:26 AM
wrong testcases!!!!!

please expalin how to get

abhilash123 @ 28 Sep 2011 01:27 AM
please expalin how to get yes or no

can we choose a single number

jayee @ 28 Sep 2011 02:34 PM
can we choose a single number at a time ?

I am still not getting why

digs2digi @ 11 Oct 2011 11:33 AM
I am still not getting why are these two statements not equal: these n-1 numbers must give the same remainder when divided by k+1 and the number not reduced to zero can give same or some other remainder and so the answer is "YES" if number of distinct remainder is <=2 and "NO" otherwise .admin wrote this on:http://discuss.codechef.com/showthread.php?p=3667#post3667

Can you add some more test

chandu_333 @ 28 Nov 2011 10:18 PM
Can you add some more test cases...Not understood question properly

Everyone is using the

anujkaliaiitd @ 21 Dec 2011 02:28 PM
Everyone is using the algorithm: xi%(k+1)==0 for all xi (except maybe 1 xi). This condition is necessary but how is it sufficient?

Can anyone please answer my

ankit0311 @ 28 Jan 2012 11:06 PM
Can anyone please answer my query in the following thread in the discussion forum? http://discuss.codechef.com/showthread.php?t=1722

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com