QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693049#8057. Best Carry Player 4SSAABBEERRWA 43ms5676kbC++201.4kb2024-10-31 15:26:072024-10-31 15:26:18

Judging History

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

  • [2024-10-31 15:26:18]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:5676kb
  • [2024-10-31 15:26:07]
  • 提交

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(r + i >= n) f = 1;
            if(b[r] <= a[i]) a[i] -= b[r], cnt += b[r], r -- ;
            else
            {
                cnt += a[i];
                b[r] -= a[i];
                a[i] = 0;
            }
        }
    }
    if(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: 5676kb

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: 5648kb

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
4
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
2
0
2
3
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
1
0
0
2
3
2
0
3
0
2
1
1
0
1
0
4
0
0
2
2
0
3
3
0
2
0
2
0
0
2
1
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
4
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
1
0
0
3
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
2
2
3
0
2
2
0
2
1
...

result:

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