QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#385888 | #8057. Best Carry Player 4 | Willis | WA | 73ms | 7928kb | C++20 | 3.2kb | 2024-04-11 09:38:48 | 2024-04-11 09:38:48 |
Judging History
answer
#ifdef local
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#endif
// #pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#ifndef local
#define endl '\n'
#endif
#define pb emplace_back
#define fi first
#define se second
// #define endl '\n'
#define rep(i, l, r) for (long long i = l; i <= r; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, x) memset(a, x, sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const double pi = acos(-1);
typedef __int128_t int128;
const ll mod = 1e18;
const db eps = 1e-9;
std::mt19937_64 rng(time(0));
ll my_random(ll l, ll r)
{
uniform_int_distribution<int> range(l, r);
return range(rng);
}
void __()
{
#ifdef local
system("pause");
#endif
}
ll qp(ll a, ll b, ll mod)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
const int maxn = 5e5 + 10;
ll a[maxn];
ll b[maxn];
ll suf[maxn];
int n;
signed main()
{
IOS;
int t = 1;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int suma = 0, sumb = 0;
for (int i = 0; i < n; i++)
suma += a[i], sumb += b[i];
if (suma > sumb)
b[0] += suma - sumb;
else if (suma < sumb)
a[0] += sumb - suma;
for (int i = 0; i <= n; i++)
suf[i] = 0;
for (int i = n - 1; i >= 0; i--)
suf[i] = suf[i + 1] + b[i];
// for (int i = 0; i < n; i++)
// cout << suf[i] << " ";
// cout << endl;
int mxa = 0;
for (int i = n - 1; i >= 0; i--)
if (a[i] > 0)
{
mxa = i;
break;
}
bool f = 0;
for (int i = n - 1; i >= 0; i--)
{
if (a[i] == 0)
continue;
ll tmp = suf[n - i];
// cout << i << " " << n - i << " " << suf[n - i] << endl;
if (tmp != 0)
f = 1;
// cout << "XXX " << f << endl;
if (f)
break;
}
if (!f)
{
cout << 0 << endl;
continue;
}
ll ans = 0;
bool f2 = 0;
int j = 0;
for (int i = n - 1; i >= 0; i--)
{
while (a[i] > 0)
{
ll bns = min(b[j], a[i]);
ans += bns;
b[j] -= bns;
a[i] -= bns;
if (bns > 0 && i + j >= n)
f2 = 1;
// cout << i << " " << j << " " << a[i] << " " << b[j] << endl;
if (b[j] == 0)
j++;
if (j == n)
break;
}
if (i + j == n - 1)
j++;
if (j == n)
break;
}
for (int i = 0; i < n; i++)
{
if (mxa + i >= n && b[i] > 0)
{
f2 = 1;
break;
}
}
if (f2)
cout << ans << endl;
else
cout << ans - 1 << endl;
}
__();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7920kb
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: 46ms
memory: 7912kb
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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 1 0 0 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: -100
Wrong Answer
time: 73ms
memory: 7844kb
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 1780759937 2531472710 2754014935 1950741996 2577893498 1671531479 1655223784 1476887044 2115933812 1332546839 958870781 600795101 927483202 2136597299 1883468626 2291627593 1436067851 2412405837 1884010446 1960543235 2014856631 848686688 1069641213 2133866856 1597069...
result:
wrong answer 4th numbers differ - expected: '2132012702', found: '1780759937'