#P9088. 「SvR-2」1+2=3

    ID: 9600 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2023网络流洛谷原创O2优化图论建模欧拉回路费用流洛谷月赛Ad-hoc

「SvR-2」1+2=3

Problem Description

You have some wooden sticks. Each stick has a number on the left and a number on the right. The numbers can only be 0,1,20,1,2. You need to connect all sticks together, and make the number of adjacent pairs whose sum is 33 as large as possible.

For example, there are two sticks 1 - 21\text{ - }2 and 1 - 01\text{ - }0. If you connect them as 1 - 0,1 - 21\text{ - }0,1\text{ - }2, then the number of adjacent pairs whose sum is 33 is 00. But if you connect them as $1\text{ - }\textcolor{red}{\underline{\textbf 2}},\textcolor{red}{\underline{\textbf 1}}\text{ - }0$, then the number of adjacent pairs whose sum is 33 is 11, because 2+1=32+1=3.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, the number of test cases.

For each test case, one line contains 99 non-negative integers, representing the counts of sticks of type $0\text{ - }0,0\text{ - }1,0\text{ - }2,1\text{ - }0,1\text{ - }1,1\text{ - }2,2\text{ - }0,2\text{ - }1,2\text{ - }2$, respectively.

Output Format

Output TT lines. Each line contains one integer, the answer.

3
4 1 3 4 7 7 9 10 3
6 3 6 4 3 4 5 6 6
6 10 7 1 4 2 6 4 2

31
23
19

Hint

Constraints

For all testdata, 1T1051\le T\le 10^5. Let ai,ja_{i,j} be the number of sticks of type i-ji\text-j. It is guaranteed that 0ai,j1090\le a_{i,j}\le 10^9.

This problem enables bundled tests and O2 optimization by default.

Let sumsum be the sum of all ai,ja_{i,j} over all test cases in one test point.

Subtask TT sumsum Special Property Score
11 1T101 \leq T \leq 10 1sum101\le sum\le 10 None 10pts10 \operatorname{pts}
22 1T501 \leq T \leq 50 1sum801\le sum\le 80 20pts20 \operatorname{pts}
33 No special limits No special limits A 15pts15\operatorname{pts}
44 B 20pts20 \operatorname{pts}
55 1T10001\le T\le 1000 C
66 No special limits None 15pts15 \operatorname{pts}

Special Property A: ai,ja_{i,j} are generated uniformly at random in [0,109][0,10^9].

Special Property B: All ai,j>0a_{i,j}>0.

Special Property C: All ai,j100a_{i,j}\le 100.

Translated by ChatGPT 5