比赛 2025.3.8 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 1+2=3 最终得分 100
用户昵称 健康铀 运行时间 7.301 s
代码语言 C++ 内存使用 3.36 MiB
提交时间 2025-03-08 11:48:44
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
inline void write(ll x) {
    if (x < 0) {
        x = ~(x - 1);
        putchar('-');
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int main() {
	freopen("123.in","r",stdin);
	    freopen("123.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = read();
    while (T--) {
        ll n00 = read();
        ll n01 = read();
        ll n02 = read();
        ll n10 = read();
        ll n11 = read();
        ll n12 = read();
        ll n20 = read();
        ll n21 = read();
        ll n22 = read();
        ll L1 = n10 + n11;
        ll R1 = n01 + n11;
        ll L2 = n20 + n22;
        ll R2 = n02 + n22;

        ll ans = 0;
        if (n12) {
            ans += n12 - 1;
            n12 = 1;
            if (L1 || R2) {
                ans++;
                n12 = 0;
            }
        }
        if (n21) {
            ans += n21 - 1;
            n21 = 1;
            if (L2 || R1) {
                ans++;
                n21 = 0;
            }
        }
        L1 -= n11;
        R1 -= n11;
        L2 -= n22;
        R2 -= n22;

        if (n11 == n22 && n11 != 0) {
            ans += n11 + n22 - 2;
            n11 = 1;
            n22 = 1;
            if (L1 || R1 || L2 || R2) {
                ans += 2;
            } else {
                ans += 1;
            }
        } else {
            ll tmp = min(n11, n22);
            ans += tmp * 2;
            n11 -= tmp;
            n22 -= tmp;
            L1 += n11;
            R1 += n11;
            L2 += n22;
            R2 += n22;
        }
        ans += min(L1, R2) + min(R1, L2);
        write(ans);
        putchar('\n');
    }

    return 0;
}