GlobeX Cup '18 S5 - Math Bash

View as PDF

Submit solution

Points: 17
Time limit: 0.6s
Java 1.0s
Memory limit: 128M

Author:
Problem type

You are taking your calculus exam. In the exam room, there is an N×N grid of desks, each with exactly one student taking an exam at that desk.

Your teacher has come up with an interesting way of grading the exams. Let pi,j represent the initial mark that the student at position (i,j) got on the exam. His actual mark, ai,j, is equal to ai,j=pi,j+ki,j where ki,j is the number of students who have an actual mark higher than or equal to student (i,j)'s initial mark and their position is (x,y) where 1x<i and 1y<j. Formally, ki,j is the number of students where ax,ypi,j and 1x<i,1y<j.

Wanting to know how much everyone's marks change, you are to find the sum of ki,j for all i,j (1i,jN).

Input Specification

The first line will contain the N (1N800).

The next line will contain N lines will each contain N space-separated integers pi,j (1pi,j109).

Output Specification

Output the sum of all ki,j, as defined above.

Sample Input 1

Copy
2
2 1
1 2

Sample Output 1

Copy
1

Explanation for Sample 1

Only the student at position (2,2) will have their mark changed. All other students will keep their current mark. Thus, k1,1=k1,2=k2,1=0, and k2,2=1. The student at position (2,2) will have their marks changed by one due to a1,1=2 (a1,1p2,2). The sum of all ki,j is therefore one.

Sample Input 2

Copy
5
1 4 2 5 3
5 2 8 4 2
1 1 1 1 3
9 9 2 3 1
1 1 1 1 1

Sample Output 2

Copy
82

Sample Input 3

Copy
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 1 2 3 4 5
10 9 8 7 6 1 2 3 4 5

Sample Output 3

Copy
1420

Comments

There are no comments at the moment.