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
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » July 2009 (Contest IV) » Sums in a cuboid

Sums in a cuboid

Problem code: CUBESUM

  • All Submissions

All submissions for this problem are available.

Suppose there is a X x Y x Z 3D matrix A of numbers having coordinates (i, j, k) where 0 i < X, 0 j < Y, 0 k < Z. Now another X x Y x Z matrix B is defined from A such that the (i, j, k) element of B is the sum of all the the numbers in A in the cuboid defined by the (0, 0, 0) and (i, j, k) elements as the diagonally opposite vertices. In other word (i, j, k) in B is the sum of numbers of A having coordinates (a, b, c) such that 0 a i, 0 b j, 0 c k. The problem is that given B, you have to find out A.

Input

The first line of input will contain the number of test cases ( 10). That many test cases will follow in subsequent lines. The first line of each test case will contain the numbers X Y Z (0 X, Y, Z 100). After that there will be X x Y lines each containing Z numbers of B. The first line contains the numbers (0, 0, 0), (0, 0, 1)..., (0, 0, Z-1). The second line has the numbers (0, 1, 0), (0, 1, 1)..., (0, 1, Z-1) and so on. The (Y+1)th line will have the numbers (1, 0, 0), (1, 0, 1)..., (1, 0, Z-1) and so on.

Output

For each test case print the numbers of A in exactly the same fashion as the input.

Example

Input:
2
3 1 1
1 
8 
22 
1 2 3
0 9 13 
18 45 51 

Output:
1 
7 
14 
0 9 4 
18 18 2 

Author: admin
Date Added: 18-06-2009
Time Limit: 1 - 10 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

pr0ton @ 1 Jul 2009 08:38 PM

What are constraints for each element in B ?

admin 2 @ 1 Jul 2009 08:42 PM

They are integers that would fit in a 32-bit integer variable.

udayj @ 2 Jul 2009 12:17 AM

Shouldn't the lower limit for X,Y,Z be 1 (according to the test case) ?

spiglerg @ 2 Jul 2009 01:14 AM

It looks like the entries are being tested with 0 size variables?
I've kept getting runtime errors until I checked for X, Y, Z>0, but I now get WA.

i0exception @ 2 Jul 2009 01:18 AM

The constraints clearly specify that X, Y, Z can be between 0 and 100 inclusive.

vermapratyush @ 2 Jul 2009 05:29 AM

how to print the output when X=0 or Y=0 or Z=0??

brilliantnut @ 2 Jul 2009 07:04 AM

The problem statement is not very clear on what happens to the input/output when either one of the dimensions is 0.

For instance, if z = 0, then do we get X x Y rows of 0 numbers each, and so does the system have to consume X x Y rows, and output X x Y blank rows, or will the input just contain no rows at all, and output no rows at all.

i0exception @ 2 Jul 2009 05:24 PM

If either of them were to be zero, there would be no input and hence no output for the case.

malcolmc @ 2 Jul 2009 06:47 PM

Are the elements of B non-negative?

i0exception @ 2 Jul 2009 07:06 PM

The elements of B will fit in a signed 32 bit integer.

sush @ 2 Jul 2009 09:12 PM

no output means not even a blank line?

admin 2 @ 2 Jul 2009 09:43 PM

@sushant Correct

mukeshsinver @ 2 Jul 2009 11:44 PM

can we know that for which test case solution gives wrong output

admin 2 @ 3 Jul 2009 12:21 AM

@mukesh No, we can't do that.

sush @ 3 Jul 2009 12:23 AM

no i am afraid not , just make sure you do not have any output when either of x,y, or z are 0. Otherwise the problem is striaghtforward

PS: i am really curious how some people solved it in under 2 seconds while mine takes 13

supercharger @ 3 Jul 2009 12:32 AM

2
3 1 1
1
8
22
1 2 3

Why there is only
8
22
Is that because they are zero, In that case how to know which are zero and which are not( I mean the which Z th number)

supercharger @ 3 Jul 2009 12:40 AM

Never mid

sush @ 3 Jul 2009 12:40 AM

in this case b[0][0][0] =1 , b[1][0][0]=8 and b[2][0][0]=22 (zero based index).....nothing is zero here

vdmedragon @ 3 Jul 2009 05:21 AM

Bug in statement : The (Y 1)th line will have the numbers (1, 0, 0), (1, 0, 1)..., (1, 0, Z-1) and so on.

vdmedragon @ 3 Jul 2009 05:24 AM

sorry, above comment is not correct.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
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 algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm 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 programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were 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 challenges 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 coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

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. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

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