QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#338103 | #8057. Best Carry Player 4 | STnofarjo# | TL | 568ms | 3864kb | C++20 | 3.6kb | 2024-02-25 17:50:12 | 2024-02-25 17:50:13 |
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 {
vector<pair<ll, ll>> rem;
ll ret = 0;
for (int j = 1; j <= m - 1; j++) {
vector<ll> ta = P, tb = Q;
if (ta[j] == 0) continue;
bool found = false;
ta[j]--;
for (int x = m - j; x <= m - 1; x++) {
if (tb[x] > 0) {
tb[x]--;
found = true;
break;
}
}
if (!found) continue;
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];
// debug(ta[i], tmp);
ll kur = min(ta[i], tmp);
// debug(kur);
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;
}
}
}
// debug(lmao);
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
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: 0
Accepted
time: 95ms
memory: 3820kb
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 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1 0 3 1 2 0 0 5 1 1 1 3 1 4 1 0 0 0 0 0 1 3 1 2 1 0 0 0 0 0 1 1 0 4 0 1 1 3 0 1 0 0 2 3 0 1 2 1 1 1 0 3 0 0 3 2 1 1 0 1 0 1 ...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 144ms
memory: 3604kb
input:
100000 5 119777838 337555280 806504015 458289944 321614229 979242871 431783189 423329635 193632121 7339369 5 189264782 667669243 753322761 861814678 224007583 977519325 104432095 940220826 712094722 903574615 5 977791540 278658984 601762324 633391706 36807634 689562032 997406456 118939957 891425821 ...
output:
1377698543 2884329841 1699584169 2132012702 2531472710 2754014935 2585135038 2577893498 2034726862 2303377730 1476887044 2618960687 1626312268 1068946376 600795101 927483202 2151016849 2256729729 2291627593 1751199962 2412405837 1884010446 2553701265 2014856631 848686688 1069641213 2412585811 167144...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 210ms
memory: 3724kb
input:
50000 10 18209490 798013131 762297136 184230300 323229686 771738936 850827138 201740028 818693101 945688434 101715068 966337103 309026840 698679951 666034197 810411289 841033024 740762082 484989962 19640395 10 608177485 700383507 317699894 982085408 908794603 92931066 880099629 965892642 576147264 9...
output:
5341540062 3811346608 3280168940 4222050470 4327730826 4389011469 5146997799 3799138189 4028437054 3650616128 4267213780 5220650313 3272450503 3560399774 5130261345 4384881302 4681302604 5415587476 2376088103 3344427945 3701410392 3434767065 4969556102 4474318648 4751503347 3701971157 5053000969 397...
result:
ok 50000 numbers
Test #6:
score: 0
Accepted
time: 568ms
memory: 3864kb
input:
5000 100 405163017 116989072 685766112 551211950 862199350 861827829 564364529 922314891 241721254 160976656 891732149 553649064 445152950 859742462 235262967 648909226 943054063 484936253 414150625 995061073 662853643 367723189 348457562 591856009 309322986 450413840 159926452 24214846 79239852 397...
output:
44348367445 47318596151 43893435579 49579921753 48669603728 45875221434 49002488594 53587378598 52208712766 49588253701 50196256163 49596309746 48141429048 49878478140 49036091100 46395088830 42672527744 41761915575 47439675311 47743457344 44672635972 50006245688 49397345810 46906644735 49589049416 ...
result:
ok 5000 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
500 1000 193550719 323493453 457420643 784509248 590688212 53858799 864840302 864699978 833248388 388148011 424847622 153776183 812936693 826657538 546327769 8986082 692715231 409800344 238099504 373879563 776749117 721714043 87525288 267321580 716697878 959194006 945266703 700945389 403532515 62661...