QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707321#8057. Best Carry Player 4Wolam#WA 51ms7988kbC++172.4kb2024-11-03 15:29:312024-11-03 15:29:35

Judging History

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

  • [2024-11-03 15:29:35]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:7988kb
  • [2024-11-03 15:29:31]
  • 提交

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-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]);
            if(cnt1[i])
            {
                mn1=min(mn1,i);
            }
            if(cnt2[q.front()])
            {
                mn2=min(mn2,q.front());
            }
            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
    {
        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;
}
/*
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
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7708kb

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: 51ms
memory: 7988kb

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'