QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693290 | #8057. Best Carry Player 4 | SSAABBEERR | WA | 43ms | 5640kb | C++20 | 1.6kb | 2024-10-31 15:54:09 | 2024-10-31 15:54:10 |
Judging History
answer
#include<bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define endl "\n"
#define ll long long
#define int long long
using namespace std;
#define pii pair<int, int>
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define pre(i, a, b) for(int i = a; i >= b; i -- )
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int N = 1e6 + 10;
int n, m, k;
int a[N], b[N];
void solve()
{
cin >> n;
int s1 = 0, s2 = 0;
rep(i, 0, n - 1) cin >> a[i], s1 += a[i];
rep(i, 0, n - 1) cin >> b[i], s2 += b[i];
if(s1 < s2) a[0] += (s2 - s1);
else b[0] += (s1 - s2);
int ma1 = 0, ma2 = 0;
rep(i, 0, n - 1)
{
if(a[i]) ma1 = i;
if(b[i]) ma2 = i;
}
if(ma1 + ma2 < n)
{
cout << 0 << endl;
return;
}
int r = n - 1, cnt = 0, f = 0;
rep(i, 0, n - 1)
{
if(i + r < n - 1) continue;
while(a[i] && r >= 0 && i + r >= n - 1)
{
if(!b[r])
{
r -- ;
continue;
}
if(r + i >= n) f = 1;
if(b[r] <= a[i]) a[i] -= b[r], cnt += b[r], b[r] = 0, r -- ;
else
{
cnt += a[i];
b[r] -= a[i];
a[i] = 0;
}
}
}
int x = 0, y = 0;
rep(i, 0, n - 1)
{
if(a[i]) x = i;
if(b[i]) y = i;
}
if(x + ma1 >= n || y + ma2 >= n || f) cout << cnt << endl;
else cout << cnt - 1 << endl;
}
signed main()
{
IOS;
int _;
_ = 1;
cin >> _;
while(_ -- )
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5632kb
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: 43ms
memory: 5640kb
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 0 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 3 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 1 0 1 2 3 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 2 1 2 0 3 4 0 2 5 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 2 1 1 0 2 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 0 0 3 2 3 0 1 2 0 1 1 ...
result:
wrong answer 12th numbers differ - expected: '1', found: '0'