QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707228#8057. Best Carry Player 4Wolam#WA 50ms7636kbC++172.4kb2024-11-03 15:12:222024-11-03 15:12:23

Judging History

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

  • [2024-11-03 15:12:23]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:7636kb
  • [2024-11-03 15:12:22]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
using ll = long long;
const int maxn = 5e5 + 10;
ll cnt1[maxn],cnt2[maxn],vis[maxn];
void solve(void)
{
    bool carry=false;
    int m,mn1=0x3f3f3f3f,mn2=0x3f3f3f3f;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>cnt1[i];
        vis[i]=cnt1[i]>0;
    }
    for(int i=0;i<m;i++)
    {
        cin>>cnt2[i];
        if(cnt2[i])
        {
            mn1=min(mn1,i);
        }
    }
    for(int i=m-2;i>=0;i--)
    {
        vis[i]|=vis[i+1];
    }
    for(int i=1;i<m;i++)
    {
        if(vis[m-i])
        {
            carry=true;
        }
    }
    queue<int> q;
    for(int i=0;i<m;i++)
    {
        q.push(i);
    }
    ll ans=0;
    bool valid=false;
    for(int i=m-1;i>=0;i--)
    {
        while(!q.empty()&&q.front()+i<m-1)
        {
            q.pop();
        }
        while(cnt1[i]&&!q.empty())
        {
            int res=min(cnt2[q.front()],cnt1[i]);
            cnt1[i]-=res;
            cnt2[q.front()]-=res;
            ans+=res;
            if(i+q.front()>=m)
            {
                valid=true;
            }
            if(cnt2[q.front()]==0)
            {
                q.pop();
            }
        }
    }
    if(valid)
    {
        ans+=cnt1[m-1];
        ans+=cnt2[m-1];
        cout<<ans<<endl;
    }
    else
    {
        if(!carry)
        {
            cout<<0<<endl;
            return;
        }
        for(int i=m-2;i>=1;i--)
        {
            if(cnt2[i]&&vis[m-i])
            {
                valid=true;
            }
        }
        // for(int i=0;i<m;i++)
        // {
        //     cout<<cnt2[i]<<" \n"[i==m-1];
        //     if(cnt2[i])
        //     {
        //         mn2=min(mn2,i);
        //     }
        // }
        ans+=cnt1[m-1];
        ans+=cnt2[m-1];
        // if(mn1==mn2||mn2==0x3f3f3f3f)
        // {
        //     ans--;
        // }
        if(!valid)
        {
            ans--;
        }
        ans=max(0ll,ans);
        cout<<ans<<endl;
    }
}
signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/*
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 50ms
memory: 7628kb

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:

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

result:

wrong answer 1st numbers differ - expected: '2', found: '1'