🏆 Luyện bài tập & THI THỬ MIỄN PHÍ HÀNG TUẦN tại oj.vietnamson.com — HSG Tin 9 · Tuyển sinh 10 chuyên Tin · HSG THPT · Quốc gia · Tin học trẻ · chấm tự động, có bảng xếp hạng & lời giải → Vào thi ngay! 🏆 THI THỬ TIN HỌC MIỄN PHÍ MỖI TUẦN tại oj.vietnamson.com → Tuyển sinh 🎓 Mình nhận đào tạo lập trình giải thuật thi đấu: thi vào lớp 10 chuyên tin · thi học sinh giỏi tin học cấp tỉnh/thành · thi vào đội tuyển quốc gia · Olympic tin học sinh viên / ICPC · phỏng vấn thuật toán. Bấm vào đây để xem thông tin khóa học → Xem khóa học

VIETNAMSON OJ · THI THỬ HÀNG TUẦN

Tuần này có kỳ thi thử

Thi như thật, chấm tự động, có lời giải chi tiết ngay sau giờ thi. Miễn phí cho mọi người. Đăng ký trước, rủ bạn bè cùng vào thử sức nhé!

Các đạo hữu, cùng nhập trận nào!
Chủ đề mới: Tu TiênMỗi đề là một chặng tu luyện: trận pháp, đan dược, bí cảnh, thiên thê…
Độ khó đã được giảmTheo góp ý của các bạn, đề vừa sức hơn so với 3 tuần trước
Tính điểm và xếp hạngKỳ thi nào cũng có bảng xếp hạng: biết ngay mình ở cảnh giới nào
Đăng ký trước từ bây giờ: đến giờ chỉ việc vào làm bài!Chưa biết cách tham gia? Xem hướng dẫn

ICPC Miền Trung 2021-2022 - Bài P: Jerry and Jelly

Nguồn: The ICPC 2021 - Vietnam Central Provincial Contest (ICPC Việt Nam vòng miền Trung 2021) – Problem PĐộ khó: Khó

Đề 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.
Ví dụ / Sample
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.

Em đã mua gói thì đăng nhập để xem. Chưa có gói thì bấm Xem giới thiệu gói để biết gói gồm những đề nào, bao nhiêu bài, học phí và ưu đãi; muốn đăng ký thì nhắn Zalo thầy Sơn.
Tự học thuật toán: khó ở đâu?
Đọc xong một bài giải là bước đầu. Phần lớn học sinh tự học sẽ gặp những trở ngại sau:
  • 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.
Học cùng thầy Nam Sơn, các trở ngại đó được gỡ bỏ:
  • 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.