QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707498#8057. Best Carry Player 4Wolam#WA 1ms7740kbC++172.3kb2024-11-03 16:14:232024-11-03 16:14:24

Judging History

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

  • [2024-11-03 16:14:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7740kb
  • [2024-11-03 16:14:23]
  • 提交

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,mx1=-0x3f3f3f3f,mx2=-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];
    }
    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;
        }
    }
    if(!carry)
    {
        cout<<0<<endl;
        return;
    }
    queue<int> q;
    for(int i=0;i<m;i++)
    {
        q.push(i);
    }
    ll ans=0;
    bool valid=false;
    for(int i=m-2;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]);
            if(cnt1[i]&&res)
            {
                mn1=min(mn1,i);
            }
            if(cnt2[q.front()]&&res)
            {
                mn2=min(mn2,q.front());
            }
            cnt1[i]-=res;
            cnt2[q.front()]-=res;
            ans+=res;
            if(i+q.front()>=m&&res)
            {
                valid=true;
            }
            if(cnt2[q.front()]==0)
            {
                q.pop();
            }
        }
    }
    if(valid)
    {
        ans+=cnt1[m-1];
        ans+=cnt2[m-1];
        cout<<ans<<endl;
    }
    else
    {
        ans+=cnt1[m-1];
        ans+=cnt2[m-1];
        cnt1[m-1]=cnt2[m-1]=0;
        for(int i=m-1;i>=0;i--)
        {
            if(cnt1[i])
            {
                mx1=max(mx1,i);
            }
            if(cnt2[i])
            {
                mx2=max(mx2,i);
            }
        }
        if(mn1>=mx1&&mn2>=mx2)
        {
            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;
}
/*
1
10
0 0 0 0 0 0 0 3 3 0
0 0 0 3 0 0 0 0 0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7740kb

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
0
1
467899
29

result:

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