[Question]
  [
As part of its compression algorithm, the JPEG standard unrolls a matrix into a vector along antidiagonals of alternating direction:
[![enter image description here](https://i.stack.imgur.com/KU5Iu.png)](https://i.stack.imgur.com/KU5Iu.png)
Your task is to take the unrolled vector along with the matrix dimensions and reconstruct the corresponding matrix. As an example:
```
[1, 2, 5, 9, 6, 3, 4, 7, 1, 2, 8, 3], 4, 3
```
should yield
```
[1 2 3 4
 5 6 7 8
 9 1 2 3]
```
whereas dimensions `6, 2` would give
```
[1 2 6 3 1 2
 5 9 4 7 8 3]
```
## Rules
You may choose to take only one of the dimensions as input. The individual inputs can be taken in any order. You may assume that the width and height are positive and valid for the given vector length.
You may assume that the vector elements are positive integers less than `10`.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
The input vector may be given in any convenient, unambiguous, flat list or string format.
The output matrix may be in any convenient, unambiguous, nested list or string format, or as a flat list along with both matrix dimensions. (Or, of course, as a matrix type if your language has those.)
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply.
## Test Cases
Each test case is of the form `vector width height => matrix`.
```
[1] 1 1                        => [[1]]
[1 2 3 1] 2 2                  => [[1 2] [3 1]]
[1 2 3 1] 4 1                  => [[1 2 3 1]]
[1 2 5 9 6 3 4 7 1 2 8 3] 3 4  => [[1 2 3] [5 6 4] [9 7 8] [1 2 3]]
[1 2 5 9 6 3 4 7 1 2 8 3] 4 3  => [[1 2 3 4] [5 6 7 8] [9 1 2 3]]
[1 2 5 9 6 3 4 7 1 2 8 3] 6 2  => [[1 2 6 3 1 2] [5 9 4 7 8 3]]
[1 2 5 9 6 3 4 7 1 2 8 3] 12 1 => [[1 2 5 9 6 3 4 7 1 2 8 3]]
[1 2 5 9 6 3 4 7 1 2 8 3] 1 12 => [[1] [2] [5] [9] [6] [3] [4] [7] [1] [2] [8] [3]]
```
## Related Challenges
* [Zigzagify a Matrix](https://codegolf.stackexchange.com/q/75587/8478) (the somewhat simpler inverse transformation)
* [Rotate the anti-diagonals](https://codegolf.stackexchange.com/q/63755/8478)
  
[Answer]
# Jelly, ~~18~~ 13 bytes
```
pS€żị"¥pỤỤị⁵s
```
Takes number of rows, number of columns and a flat list as separate command-line arguments.
My code is almost identical to [the one in the twin challenge](https://codegolf.stackexchange.com/a/75590). The only differences are an additional `Ụ` (which inverts the permutation of the indices) and an `s` (to split the output into a 2D array).
[Try it online!](http://jelly.tryitonline.net/#code=cFPigqzFvOG7iyLCpXDhu6Thu6Thu4vigbVz&input=&args=NA+Mw+WzEsIDIsIDUsIDksIDYsIDMsIDQsIDcsIDEsIDIsIDgsIDNd)
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 29 bytes
```
:!i:+-1y^8MtsQ/*-X:4#S2$S1GZC
```
Input is `height`, `width`, `vector` separated by newlines.
This reuses part of the code in [my answer to the related challenge](https://codegolf.stackexchange.com/a/75595/36398).
[**Try it online!**](http://matl.tryitonline.net/#code=OiFpOistMXleOE10c1EvKi1YOjQjUzIkUzFHWkM&input=Mwo0ClsxIDIgNSA5IDYgMyA0IDcgMSAyIDggM10)
### Explanation
```
:!      % take number of rows, r, as input. Generate column vector [1;2;...;r]
i:      % take number of columns, c, as input. Generate row vector [1,2,...,c] 
+       % add with broadcast. Gives 2D array
-1      % push -1
y^      % duplicate previous 2D array. Compute -1 raised to that
8M      % push [1;2;...;r] again
tsQ/    % divide by its sum plus 1
*       % multiply
-       % subtract
X:      % linearize 2D array into column array
4#S     % sort and push the indices of the sorting. Gives a column vector
2$S     % take vector as input. Sort it according to previous column vector
1G      % push r
ZC      % reshape into columns of r elements
```
[Answer]
# J, 24 bytes
```
]$({~[:/:@;[:<@|.`</.i.)
```
Also uses the oblique adverb `/.` to perform zigzagify as in the J [answer](https://codegolf.stackexchange.com/a/75594/6710) from that [challenge](https://codegolf.stackexchange.com/questions/75587/zigzagify-a-matrix).
## Usage
Input is with the array on the LHS and the dimensions `[height, width]` on the RHS.
```
   f =: ]$({~[:/:@;[:<@|.`</.i.)
   1 f 1 1
1
   1 2 3 1 f 2 2
1 2
3 1
   1 2 5 9 6 3 4 7 1 2 8 3 f 4 3
1 2 3
5 6 4
9 7 8
1 2 3
   1 2 5 9 6 3 4 7 1 2 8 3 f 3 4
1 2 3 4
5 6 7 8
9 1 2 3
   1 2 5 9 6 3 4 7 1 2 8 3 f 2 6
1 2 6 3 1 2
5 9 4 7 8 3
   1 2 5 9 6 3 4 7 1 2 8 3 f 1 12
1 2 5 9 6 3 4 7 1 2 8 3
   1 2 5 9 6 3 4 7 1 2 8 3 f 12 1
1
2
5
9
6
3
4
7
1
2
8
3
```
## Explanation
```
]$({~[:/:@;[:<@|.`</.i.)  Input: list A (LHS), dimensions D (RHS)
                     i.   Range shaped to D
           [:<@|.`</.     Zigzagify that matrix
     [:   ;               Raze the boxes to get a zigzagify permutation
       /:@                Invert that permutation to get an unzigzagify permutation
   {~                     Apply that permutation to A
]                         Get D
 $                        Shape that permutation to D and return
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 36 bytes
```
{y#x@<,/((#c)#(|:;::))@'c:.=+/!y:|y}
```
[Try it online!](https://ngn.codeberg.page/k#eJyFj1EKgzAQRP/3FFv8MKGhsjFa3bTgT2/gDQTPUNH27N0VCwrVfu68TGam53FIns3NZcYknU3MxJHZ2ibt+HI/Z6eBp+EF0LIxjiIhWUA0hB5zpOjRb+6w4gXWWIoa8Ip6V5hHuQ55wPyQl6u8X5z8nwIywFsL8GDjHMH8UFqpyS0jYJkTC3GHWIu7irNiv0hkhQpq3CDN0y81W3OrGbmdOkLSHaQd332TpS18APpFSKA=)
Basically the same as [Zagify a matrix](https://codegolf.stackexchange.com/a/254384/111844) but with a grade.
]