We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 71ddba0 commit e664089Copy full SHA for e664089
src/main/kotlin/p34xx/Problem3446.kt
@@ -7,20 +7,16 @@ fun main() {
7
fun sortMatrix(grid: Array<IntArray>): Array<IntArray> {
8
return grid.indices.flatMap { r ->
9
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
+ }.groupBy { (it.first - it.second) *2+1 }.flatMap { (diff, positions) ->
+ positions.sortedWith { (r1, c1), (r2, c2) ->
+ (grid[r2][c2] - grid[r1][c1]) * diff
+ }.let { sorted ->
+ positions.indices.map { positions[it] to grid[sorted[it].first][sorted[it].second] }
15
}
16
17
- positions.indices.map { positions[it] to sorted[it] }
18
}.toMap().let {
19
Array(grid.size) { r ->
20
IntArray(grid[r].size) { c ->
21
- it[r to c]?.let { (tr, tc) ->
22
- grid[tr][tc]
23
- } ?: 0
+ it[r to c] ?: 0
24
25
26
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments