QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#337959#8057. Best Carry Player 4STnofarjo#WA 90ms3648kbC++203.3kb2024-02-25 16:26:522024-02-25 16:26:52

Judging History

你现在查看的是最新测评结果

  • [2024-02-25 16:26:52]
  • 评测
  • 测评结果:WA
  • 用时:90ms
  • 内存:3648kb
  • [2024-02-25 16:26:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tc template <class
tc T1, class T2 > ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
tc T, class = decay_t<decltype(*begin(declval<T>()))>, class = enable_if_t < !is_same<T, string>::value >> ostream &operator<<(ostream &os, const T &c) {
    os << '{';
    for (auto it = c.begin(); it != c.end(); ++it) os << &", "[2 * (it == c.begin())] << *it;
    return os << '}';
}
#define PARENS ()
#define EEE(...) EEE1(EEE1(__VA_ARGS__))
#define EEE1(...) EEE2(__VA_ARGS__)
#define EEE2(...) __VA_ARGS__
#define REP(macro, ...) __VA_OPT__(EEE(REP_HELPER(macro, __VA_ARGS__)))
#define REP_HELPER(macro, a1, ...) macro(a1) __VA_OPT__(REP_AGAIN PARENS(macro, __VA_ARGS__))
#define REP_AGAIN() REP_HELPER
#define out(x) "\t[" << #x " = " << x << "]\n"
#ifdef LOCAL
#define debug(...) cerr << "Line " << __LINE__ << "\n" \
                        << REP(out, __VA_ARGS__) << "\n";
#else
#define debug(...) "itfeelsliketimeispassingsoquickly.thepassageoftimedependsentirelyonwhereyou'restanding.relativitytheory...it'ssoromantic.butit'sjustsotragictoo."
#endif

const int INF = 2e9;

void el_psy_congroo() {
    int m;
    cin >> m;
    vector<ll> A(m), B(m);
    for (int i = 0; i < m; i++) cin >> A[i];
    for (int i = 0; i < m; i++) cin >> B[i];

    const function<ll(vector<ll>, vector<ll>)> go = [&](vector<ll> P, vector<ll> Q) -> ll {
        vector<pair<ll, ll>> rem;
        ll ret = 0;

        ll dP = accumulate(P.begin(), P.end(), 0ll);
        ll dQ = accumulate(Q.begin(), Q.end(), 0ll);

        for (int j = 1; j <= m - 1; j++) {
            vector<ll> ta = P, tb = Q;
            if (ta[j] == 0 || tb[m - j] == 0) continue;
            ta[j]--, tb[m - j]--;
            ll lmao = 0, tmp = 0;
            for (int i = 0; i < m; i++) {
                rem.emplace_back(tb[m - 1 - i], m - 1 - i);
                tmp += tb[m - 1 - i];
                ll kur = min(ta[i], tmp);
                lmao += kur;
                ta[i] -= kur;
                tmp -= kur;

                ll buf = 0;
                while (true) {
                    if (buf + rem.back().first > kur) {
                        pair<ll, ll> last = rem.back();
                        rem.pop_back();
                        tb[last.second] -= (kur - buf);
                        rem.emplace_back(last.first - (kur - buf), last.second);
                        break;
                    } else {
                        buf += rem.back().first;
                        tb[rem.back().second] = 0;
                        rem.pop_back();
                        if (buf == kur) break;
                    }
                }
            }
            if (lmao >= min(dP, dQ) - 1) {
                ret = max(ret, 1 + lmao + tb[m - 1]);
            } else {
                ret = max(ret, 1 + lmao);
            }
        }
        return ret;
    };

    ll ans = max(go(A, B), go(B, A));
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int TC = 1;
    cin >> TC;
    for (int i = 1; i <= TC; i++) {
        el_psy_congroo();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

input:

5
2
1 2
3 4
3
1 0 1
0 1 0
4
1 0 0 1
1 1 1 1
5
123456 114514 1919810 233333 234567
20050815 998244353 0 0 0
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0

output:

5
1
2
467900
29

result:

ok 5 number(s): "5 1 2 467900 29"

Test #2:

score: -100
Wrong Answer
time: 90ms
memory: 3648kb

input:

100000
5
0 1 1 1 1
0 0 1 0 0
5
0 0 0 0 0
1 1 1 0 0
5
0 0 2 1 1
0 2 1 0 1
5
0 0 0 0 0
1 2 1 0 0
5
0 1 0 1 1
0 0 1 1 1
5
2 0 0 0 1
1 0 0 0 3
5
2 0 0 1 1
0 2 1 1 1
5
0 0 0 0 2
0 0 0 0 1
5
0 0 0 0 0
0 1 1 0 0
5
4 0 0 0 0
0 0 0 1 0
5
0 0 0 0 1
2 1 1 0 0
5
0 2 3 0 0
0 0 0 1 0
5
1 1 1 0 1
1 0 1 0 1
5
0 0 0...

output:

2
0
4
0
3
0
3
0
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
0
0
2
3
3
0
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
0
0
2
0
0
0
2
0
1
0
1
0
4
0
0
0
2
0
3
3
0
2
0
0
0
0
1
1
2
0
0
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
0
2
0
1
3
1
1
0
0
0
0
0
3
2
0
0
0
0
1
0
1
0
0
0
4
1
0
0
2
0
2
0
2
0
0
0
3
0
3
1
0
2
0
3
0
1
2
0
0
1
...

result:

wrong answer 6th numbers differ - expected: '3', found: '0'