5/17/25, 8:13 PM Problem - B - Codeforces
gbsk12345 | Logout
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP
PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION
Codeforces Round 1025 (Div. 2)
B. Slice to Survive
Contest is running
time limit per test: 1 second
memory limit per test: 256 megabytes 02:06:05
Duelists Mouf and Fouad enter the arena, which is an 𝑛 × 𝑚 grid! Contestant
Fouad's monster starts at cell (𝑎, 𝑏), where rows are numbered 1 to 𝑛 and columns 1 to 𝑚.
Mouf and Fouad will keep duelling until the grid consists of only one cell.
→ Submit?
In each turn:
Mouf first cuts the grid along a row or column line into two parts, discarding the part without Language: GNU GCC C11 5.1.0
Fouad's monster. Note that the grid must have at least two cells; otherwise, the game has
already ended. Choose
Choose File No file chosen
file:
After that, in the same turn, Fouad moves his monster to any cell (possibly the same one it
Be careful: there is 50 points penalty for
was in) within the remaining grid.
submission which fails the pretests or
resubmission (except failure on the first test,
denial of judgement or similar verdicts).
"Passed pretests" submission verdict doesn't
guarantee that the solution is absolutely
correct and it will pass system tests.
Submit
Visualization of the phases of the fourth test case.
Mouf wants to minimize the number of turns, while Fouad wants to maximize them. How many
turns will this epic duel last if both play optimally? → Score table
Input Score
Each test contains multiple test cases. The first line contains the number of test cases 𝑡 ( Problem A 484
1 ≤ 𝑡 ≤ 104 ). The description of the test cases follows.
Problem B 968
The first and only line of each test case contains four integers 𝑛, 𝑚, 𝑎, and 𝑏 (2 ≤ 𝑛, 𝑚 ≤ 10 ,
9
Problem C1 1210
1 ≤ 𝑎 ≤ 𝑛 , 1 ≤ 𝑏 ≤ 𝑚) — denoting the number of rows, the number of columns, the starting
row of the monster, and the starting column of the monster, respectively. Problem C2 726
Problem C3 484
Output
For each test case, output a single integer — the number of turns this epic duel will last if both Problem D 1694
play optimally. Problem E 2420
Example Problem F 2904
input Copy Successful hack 100
8 Unsuccessful hack -50
2 2 1 1
3 3 2 2 Unsuccessful submission -50
2 7 1 4
2 7 2 2 Resubmission -50
8 9 4 6 * If you solve problem on 00:08 from the first attempt
9 9 5 5
2 20 2 11
22 99 20 70
output Copy
2
4
4
3
[Link] 1/2
5/17/25, 8:13 PM Problem - B - Codeforces
6
8
6
10
Note
In the first test case, one possible duel sequence is as follows:
Turn 1: Mouf cuts the grid horizontally along the line between the rows 1 and 2, removing the
bottom half and leaving a 1 × 2 grid.
Turn 1: Fouad's monster is at the cell (1, 1).
Turn 2: Mouf cuts the 1 × 2 grid again, removes one column, and isolates the cell (1, 1).
The duel is completed in 2 turns.
In the fourth case, one possible duel sequence is as follows:
Turn 1: Mouf cuts the grid vertically along the line between the columns 2 and 3, splitting it
into a 2 × 2 and a 2 × 5 field, then removes the 2 × 5 part.
Turn 1: Fouad moves the monster to the cell (1, 1).
From this point on, the duel plays out just like the first test case—two more turns trim down
the grid from 2 × 2 to a single 1 × 1 cell.
In total, the duel is completed in 3 turns.
You can refer to the pictures mentioned in the problem statement for illustrations of the fourth
test case.
Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: May/17/2025 20:13:48UTC+5.5 (k2).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions
Supported by
[Link] 2/2