QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#338153 | #8057. Best Carry Player 4 | STnofarjo# | WA | 71ms | 3656kb | C++20 | 3.7kb | 2024-02-25 18:30:37 | 2024-02-25 18:30:37 |
Judging History
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];
ll dA = accumulate(A.begin(), A.end(), 0ll);
ll dB = accumulate(B.begin(), B.end(), 0ll);
if (dA < dB)
A[0] += (dB - dA);
else if (dB < dA)
B[0] += (dA - dB);
const function<ll(vector<ll>, vector<ll>)> go = [&](vector<ll> P, vector<ll> Q) -> ll {
queue<pair<ll, ll>> rem;
ll ret = 0;
vector<ll> ta = P, tb = Q;
bool ada_start_carry = false;
ll lmao = 0, tmp = 0;
for (int i = 0; i < m; i++) {
rem.emplace(tb[m - 1 - i], m - 1 - i);
tmp += tb[m - 1 - i];
ll kur = min(ta[i], tmp);
lmao += kur;
tmp -= kur;
ll buf = 0;
while (true) {
if (buf + rem.front().first > kur) {
pair<ll, ll> last = rem.front();
if (last.second + i >= m) {
ada_start_carry = true;
}
rem.pop();
tb[last.second] -= (kur - buf);
rem.emplace(last.first - (kur - buf), last.second);
break;
} else {
if (rem.front().second + i >= m) {
ada_start_carry = true;
}
buf += rem.front().first;
tb[rem.front().second] = 0;
rem.pop();
if (buf == kur) break;
}
}
}
if (!ada_start_carry) {
ll tot = 0;
for (int j = m - 1; j >= 1; j--) {
tot += Q[j];
if (tot > 0 && P[m - j] > 0) {
ada_start_carry = true;
break;
}
}
if (!ada_start_carry) return 0;
ret = max(ret, lmao - 1);
} else {
ret = max(ret, lmao);
}
return ret;
};
// debug(go(A, B), go(B, A));
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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: 71ms
memory: 3656kb
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 3 3 2 0 0 1 1 3 1 3 1 1 0 0 0 1 1 4 1 4 1 0 2 3 3 1 5 1 0 2 1 1 1 1 0 1 3 5 3 2 2 2 0 1 2 3 2 0 3 1 2 1 1 0 1 0 4 2 2 2 2 0 3 3 0 2 0 1 0 1 2 1 2 1 3 4 0 2 5 0 2 1 1 1 0 3 2 3 0 2 1 4 3 3 1 2 2 2 1 3 1 1 0 1 0 1 0 3 2 2 0 2 1 1 1 2 0 1 2 4 1 3 3 2 2 2 0 2 0 1 2 3 1 3 1 0 3 2 3 0 1 2 0 1 1 ...
result:
wrong answer 14th numbers differ - expected: '0', found: '1'