Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e664089

Browse files
1
1 parent 71ddba0 commit e664089

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

‎src/main/kotlin/p34xx/Problem3446.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ fun main() {
77
fun sortMatrix(grid: Array<IntArray>): Array<IntArray> {
88
return grid.indices.flatMap { r ->
99
grid[r].indices.map { r to it }
10-
}.groupBy { it.first - it.second }.flatMap { (diff, positions) ->
11-
val d = diff *2+1
12-
13-
val sorted = positions.sortedWith { (r1, c1), (r2, c2) ->
14-
(grid[r2][c2] - grid[r1][c1]) * d
10+
}.groupBy { (it.first - it.second) *2+1 }.flatMap { (diff, positions) ->
11+
positions.sortedWith { (r1, c1), (r2, c2) ->
12+
(grid[r2][c2] - grid[r1][c1]) * diff
13+
}.let { sorted ->
14+
positions.indices.map { positions[it] to grid[sorted[it].first][sorted[it].second] }
1515
}
16-
17-
positions.indices.map { positions[it] to sorted[it] }
1816
}.toMap().let {
1917
Array(grid.size) { r ->
2018
IntArray(grid[r].size) { c ->
21-
it[r to c]?.let { (tr, tc) ->
22-
grid[tr][tc]
23-
} ?: 0
19+
it[r to c] ?: 0
2420
}
2521
}
2622
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /