QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412081#8057. Best Carry Player 4ucup-team1716#WA 55ms3672kbC++201.7kb2024-05-16 03:37:322024-05-16 03:37:33

Judging History

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

  • [2024-05-16 03:37:33]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:3672kb
  • [2024-05-16 03:37:32]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int t = 1;
	cin >> t;
    while(t-->0)
    {
        int n;
        cin >> n;

        vector<ll> a(n), b(n);
        for(int i=0; i<n; i++) cin >> a[i];
        for(int i=0; i<n; i++) cin >> b[i];

        ll suma = 0, sumb = 0;
        for(int i=0; i<n; i++)
        {
            suma += a[i];
            sumb += b[i];
        }

        if(suma < sumb) a[0] += sumb - suma;
        else b[0] += suma - sumb;

        bool ok = false;
        int index1 = n-1, index2 = 0;
        ll ans = 0;

        vector<ll> p, q(n, 0);

        for(index1 = n-1; index1 >= 0; index1--)
        {
            index2 = max(index2, n - 1 - index1);
            while(index2 != n && a[index1] > 0)
            {
                ll m = min(a[index1], b[index2]);
                //cout << "!! " << m << " " << index1 << "\n";
                if(m > 0) p.pb(index1);
                a[index1] -= m;
                b[index2] -= m;
                ans += m;
                if(index1 + index2 >= n) ok = true;
                if(b[index2] == 0) index2++;
            }
        }

        reverse(p.begin(), p.end());
        int k = p.size(), now = 0;
        ll sum = 0;
        for(int i=0; i<n; i++)
        {
            while(now < k && p[now] == i)
            {
                //cout << "! " << p[now] << " " << sum << "\n";
                if(sum > 0) ok = true;
                now++;
            }
            sum += b[n - 1 - i];
        }

        cout << max(0LL, ans - 1 + ok) << "\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

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: 55ms
memory: 3640kb

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

result:

wrong answer 16th numbers differ - expected: '0', found: '1'