QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593660#8057. Best Carry Player 4Rosmontispes#WA 77ms3772kbC++202.6kb2024-09-27 15:23:542024-09-27 15:23:55

Judging History

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

  • [2024-09-27 15:23:55]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:3772kb
  • [2024-09-27 15:23:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18;
void O_o()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        cin>>b[i];
    a[0]=inf;
    b[0]=inf;
    vector<int> c(n);//i + n-i-1
    int ans=0;
    for(int i=0; i<n; i++)
    {
        c[i]=min(a[i],b[n-i-1]);
        ans+=c[i];
    }

    //check whether the remaining numbers can achieve n
    vector<int> ra(n),rb(n);
    set<int> s;
    for(int i=0; i<n; i++)
    {
        ra[i]=a[i]-c[i];
        rb[n-i-1]=b[n-i-1]-c[i];
    }
    for(int i=0; i<n; i++)
    {
        if(rb[i]>0);
            s.insert(i);
    }
    int tot=0;
    for(int i=0; i<n; i++)
    {
        while(ra[i]>0)
        {
            auto it=s.lower_bound(n-i);
            if(it==s.end()) break;
            int num=min(ra[i],rb[*it]);
            tot+=num;
            ra[i]-=num;
            rb[*it]-=num;
            if(!rb[*it])
                s.erase(it);
        }
    }
    if(tot>0)
    {
        cout<<ans+tot<<"\n";
        return;
    }

    //replace a pair == n-1 by n
    vector<int> p,q;
    for(int i=0; i<n; i++)
    {
        ra[i]=a[i]-c[i];
        rb[n-i-1]=b[n-i-1]-c[i];
    }
    for(int i=0; i<n; i++)
    {
        if(a[i])
            p.push_back(i);
        if(b[i])
            q.push_back(i);
    }
    for(int i=0; i<n; i++)
    {
        if(ra[i])
        {
            int t=n-i;
            auto it=lower_bound(q.begin(),q.end(),t);
            if(it!=q.end())
            {
                cout<<ans<<"\n";
                return;
            }
        }
        if(rb[i])
        {
            int t=n-i;
            auto it=lower_bound(p.begin(),p.end(),t);
            if(it!=p.end())
            {
                cout<<ans<<"\n";
                return;
            }
        }
    }

    //replace two pairs == n-1 by a pair == n
    for(auto i:p)
    {
        int t=n-i;
        auto it=lower_bound(q.begin(),q.end(),t);
        if(it!=q.end())
        {
            cout<<ans-1<<"\n";
            return;
        }
    }
    for(auto i:q)
    {
        int t=n-i;
        auto it=lower_bound(p.begin(),p.end(),t);
        if(it!=p.end())
        {
            cout<<ans-1<<"\n";
            return;
        }
    }

    //no? ans=0
    cout<<"0\n";
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)
    {
        O_o();
    }
}

详细

Test #1:

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

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: 77ms
memory: 3548kb

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

result:

wrong answer 5th numbers differ - expected: '3', found: '4'