atcoder#ARC158E. [ARC158E] All Pair Shortest Paths
[ARC158E] All Pair Shortest Paths
Score : points
Problem Statement
We have a grid with rows and columns. Let denote the square at the -th row from the top and -th column from the left. has a postive integer written on it.
Two squares are said to be adjacent when they share a side.
A path from square to is a sequence of distinct squares such that , , and and are adjacent for every . Additionally, the weight of that path is the sum of integers written on .
For two squares and , let denote the minimum weight of a path from to . Find the sum of over all pairs of squares , modulo .
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the sum of over all pairs of squares , modulo .
1
3
5
24
You should find the sum of the following four values.
- For : .
- For : .
- For : .
- For : .
2
1 2
3 4
76
5
1 1000000000 1 1 1
1 1 1 1000000000 1
66714886