ICPC Miền Trung 2021-2022 - Bài P: Jerry and Jelly
Đề bài
P. Jerry and Jelly
Standard I/O | Time Limit: 2s | Memory Limit: 512 MB
(Python on oj.vietnamson.com: 3s)
Jerry's 24th birthday is coming! Like all other mice, the age of 24 is a very important milestone in his life. On this occasion, he invites lots of his friends to his house for a very special party. After having waited for Tom to fall asleep, Jerry silently broke into a fridge and found a very big piece of grass jelly there! He silently brought the jelly piece away and... it's time for joy!
The piece of jelly Jerry stole is a rectangular whose dimensions are $x, y$ and $z$, respectively. Jerry wants to split it into several smaller pieces by making several cuts. So as to make the jelly pieces look tasty, every Jerry's cut must split some piece into exactly two smaller pieces which are also rectangulars with integer dimensions. Moreover, a cut must be parallel to at least one faces of the piece being cut as well.
After cutting the jelly, Jerry will put jelly pieces into a plate. While placing a piece, Jerry always rotate the piece so that its largest face lies on the plate. Formally, suppose that the dimensions of a piece are $a, b$ and $c$ where $a \ge b \ge c$, its surface area should always be $a \times b$ and its height should always equal to $c$.
Jerry only considers a piece of jelly cute when its height is at least $u$. He will only put cute pieces of jelly onto the plate while throwing away all non-cute pieces. For a beautiful plate of jelly, he wants the total surface area of jelly pieces on the plate to be as large as possible.
Jerry would like to know the maximum value of total surface area of all cute jelly pieces on the plate, before making any cuts to his delicious jelly. He is very good at hiding, running and stealing; but not programming. So please help him!
Input
The first line of the input contains one integer $\tau$ $(1 \le \tau \le 10^5)$ denoting the number of test cases. In the rest $\tau$ lines, each presents a test case with 4 positive integers $x, y, z$ and $u$ $(1 \le x, y, z, u \le 100)$ where $x, y, z$ are dimensions of the stolen jelly peace and $u$ is the minimum height of a cute jelly piece.
Output
For each test case, print a single integer on a line, representing the maximum possible value of total surface area of all jelly pieces on the plate.
Explanation
In the first test case, Jerry got a rectangular piece of jelly with dimensions (5, 4, 3). He should cut it into two rectangular pieces with dimensions (5, 2, 3) and put these two pieces onto the plate. Both pieces' surface areas equal to 5 × 3 = 15 and both pieces' heights equal to 2. Hence the total surface area is 15 + 15 = 30.
In the second test case, since every piece's height is at least 1, the piece is always cute. Hence, Jerry can cut the initial jelly piece with dimensions (4, 3, 2) into 4 × 3 × 2 = 24 cubes of side 1. Each cube's surface area is 1.
Note (VIETNAMSON)
- Problem of The ICPC 2021 - Vietnam Central Provincial Contest (University of Science and Technology - The University of Danang). The statement and samples are kept verbatim from the original PDF.
- "Rectangular" means a rectangular box (cuboid). The "surface area" of a piece on the plate is the area of the face lying on the plate ($a \times b$). If no piece is cute, the answer is 0.
- Python on oj.vietnamson.com: time limit 3 s, memory limit 1 GB.
Input
2
5 4 3 2
4 3 2 1
Output
30
24Ý tưởng và lời giải chi tiết
Phần phân tích ý tưởng, các cách giải từ cơ bản đến tối ưu kèm code C++/Python và chấm thử trên VIETNAMSON OJ dành cho học viên đã đăng ký gói.
- Không biết học gì trước, học gì sau, học lan man nên kiến thức bị hổng.
- Bí bài không ai gỡ, ngồi cả buổi vẫn không ra rồi bỏ cuộc.
- Code chạy được nhưng không đủ điểm, không biết sai ở đâu, chậm ở đâu.
- Không có đề thi thử và người chấm, nên không biết mình đang ở mức nào.
- Dễ nản giữa chừng khi không có ai theo sát.
- Lộ trình 111 buổi video sắp sẵn từ dòng code đầu tiên đến đề HSG thật của các tỉnh.
- Thầy trực tiếp gỡ bí, chữa bài cho từng em qua nhóm Zalo riêng.
- Hệ thống chấm bài tự động 24/7 và thi thử HSG hằng tuần để biết chính xác mình đang ở đâu.
- Đóng học phí một lần, thầy kèm lâu dài: từ thi chuyên Tin đến HSG quốc gia và cả khi lên đại học.
