QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350490#8057. Best Carry Player 4PPP#WA 52ms3612kbC++141.6kb2024-03-10 19:28:262024-03-10 19:28:26

Judging History

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

  • [2024-03-10 19:28:26]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3612kb
  • [2024-03-10 19:28:26]
  • 提交

answer

//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define X first
#define Y second


const ll mod = 1000000007;
//const ll mod = 998244353;





void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (ll i=0;i<n;i++) cin >> a[i];
    for (ll i=0;i<n;i++) cin >> b[i];
    ll Sa = 0, Sb = 0;
    for (ll i=0;i<n;i++)
    {
        Sa += a[i];
        Sb += b[i];
    }
    if (Sa>Sb) b[0] += Sa-Sb;
    else a[0] += Sb-Sa;
    vector<ll> a0 = a, b0 = b;
    ll A = 0;
    ll ok = 0;
    for (ll i=0,j=n-1;i<n;i++)
    {
        while (a[i]>0 and j>=0 and i+j>=n-1)
        {
            if (b[j]==0)
            {
                j--;
                continue;
            }
            ll D = min(a[i],b[j]);
            a[i] -= D, b[j] -= D;
            A += D;
            if (i+j>=n) ok = 1;
        }
    }
    if (ok==1)
    {
        cout << A << "\n";
        return;
    }
    if (A==0)
    {
        cout << 0 << "\n";
        return;
    }
    ll mxi = -1, mni = mod;
    for (ll w=0;w<n;w++)
    {
        if (a[w]>0) mxi = max(w,mxi);
        if (a0[w]>a[w]) mni = min(w,mni);
    }
    if (mni<mxi) ok = 1;
    mxi = -1, mni = mod;
    for (ll w=0;w<n;w++)
    {
        if (b[w]>0) mxi = max(w,mxi);
        if (b0[w]>b[w]) mni = min(w,mni);
    }
    if (mni<mxi) ok = 1;
    if (ok==0) A--;
    cout << A << "\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll T;
    T = 1;
    cin >> T;
    while (T--) solve();
}

詳細信息

Test #1:

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

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: 52ms
memory: 3612kb

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
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
2
0
1
2
2
2
0
3
0
2
1
1
0
1
0
4
1
1
2
2
0
3
3
0
2
0
1
0
0
1
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
1
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
0
1
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 63rd numbers differ - expected: '0', found: '1'