CCC '16 J2 - Magic Squares

View as PDF

Submit solution


Points: 3
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2016 Stage 1, Junior #2

Magic Squares are square arrays of numbers that have the interesting property that the numbers in each column, and in each row, all add up to the same total.

Given a 4 \times 4 square of numbers, determine if it is a magic square.

Input Specification

The input consists of four lines, each line having 4 space-separated integers.

Output Specification

Output either magic if the input is a magic square, or not magic if the input is not a magic square.

Sample Input 1

16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

Output for Sample Input 1

magic

Explanation for Output for Sample Input 1

Notice that each row adds up to 34, and each column also adds up to 34.

Sample Input 2

5 10 1 3
10 4 2 3
1 2 8 5
3 3 5 0

Output for Sample Input 2

not magic

Explanation for Output for Sample Input 2

Notice that the top row adds up to 19, but the rightmost column adds up to 11.


Comments


  • 1
    Icarus  commented on Feb. 22, 2024, 6:20 p.m.

    editorial too hard for me.

    ez sol: sum row and col and see if they =

    skill isue if u cant solve


  • 3
    jasonshen806  commented on Nov. 4, 2023, 2:04 a.m.

    This is one of the hardest J2's I have ever done.


    • -1
      kittycornanna1  commented on Feb. 13, 2024, 1:07 a.m.

      It's actually not that hard if you write many lines.


      • 0
        Vinson  commented on Feb. 21, 2024, 6:10 p.m.

        Facts


  • 9
    Winbigwok  commented on March 24, 2020, 1:40 a.m.

    test cases too weak just need to check rows


    • 2
      maxcruickshanks  commented on April 15, 2022, 6:58 p.m.

      Since the original data were weak, 2 more test cases were added to prevent this solution, and all submissions were rejudged.


  • 8
    2405873453  commented on Jan. 15, 2020, 5:03 a.m.

    Everyone, if you are using java to solve this question,and having a wa because of "presentation",remember to use System.out.println instead of just print, the grader has some little problem because it is tesing all the case together, so if your out put don't move to the nxt line, what domj grader will see is something like"magicmagicnot magicmagic"


  • 21
    Plasmatic  commented on March 4, 2019, 2:43 p.m. edit 2

    this must be the predecessor to what is probably the most controversial CCC problem of all time