F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Black Magic

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 575    Accepted Submission(s): 297


Problem Description
HoshiYo is learning Black Magic with $n$ blocks. The left and right sides of each block are painted black or white. HoshiYo arranges the blocks in a row in a certain order without rotating them and then releases the Black Magic. Here's what happens next:
  • For any two adjacent blocks, if the right side of the left block and the left side of the right block are both painted black, then the two sides will be pasted together making the two blocks into one.
HoshiYo wants to know the minimum and maximum blocks he can get after releasing the Black Magic.
 

Input
The first line contains an integer $T$ ($1 \le T \le 4\times 10^3$), indicating the number of test cases.

Each test case contains four integers $E,L,R,B$ ($0 \le E,L,R,B \le 10^5, E+L+R+B\ge 1$), indicating the number of blocks.
  • $E$: the number of blocks whose both sides are painted white.
  • $L$: the number of blocks whose left side is painted black and right side is painted white.
  • $R$: the number of blocks whose right side is painted black and left side is painted white.
  • $B$: the number of blocks whose both sides are painted black.
It guaranteed that the sum of $E+L+R+B$ over all test cases won't exceed $10^6$.
 

Output
For each test case, output two integers in a single line, indicating the minimum and maximum blocks HoshiYo can get.
 

Sample Input
3 1 1 1 1 1 2 3 4 3 4 5 6
 

Sample Output
2 4 4 8 8 16
 

Hint
Let's denote a block by $(x,y)$, where $x$ indicates the color on the left side, and $y$ indicates the color on the right side. We use $0$ to represent white and $1$ to represent black.

For the first test case in the sample, here is a possible solution to get the minimum number of blocks:

$$(0,0) \quad (0,1) \quad (1,1) \quad (1,0)$$

As shown above, the last three blocks will be pasted into one.

And here is a possible solution to get the maximum number of blocks:

$$(0,0) \quad (1,0) \quad (1,1) \quad (0,1)$$

As shown above, any two blocks will not be pasted together.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-04 09:39:03, Gzip enabled