QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569410#8057. Best Carry Player 4gates_orzWA 59ms5704kbC++172.6kb2024-09-16 22:38:392024-09-16 22:38:39

Judging History

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

  • [2024-09-16 22:38:39]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:5704kb
  • [2024-09-16 22:38:39]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

typedef long long LL;
#define int LL
#define inl inline
const int N = 5e5 + 10;
const int M = N * 2;
//const int mod=998244353;
const int mod = 1000000007;
const double eps = 1e-8;
//const int mod=1e9+7;
typedef pair<int,int> PII;
//const int INF=0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int n, m;

void become_faster() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int sa[N],sb[N];
void solve() {
    cin>>m;
    int sum1=0,sum2=0;
    for(int i=0;i<m;i++)cin>>sa[i],sum1+=sa[i];
    for(int i=0;i<m;i++)cin>>sb[i],sum2+=sb[i];
    int p1 = 0, p2 = 0;
    if(sum1<sum2)sa[0]+=sum2-sum1;
    else sb[0]+=sum1-sum2;
    for (int i = m - 2; i >= 0; i--) {
        if (sa[i]) {
            p1=i;
            break;
        }
    }
    for(int i=m-2;i>=0;i--) {
        if(sb[i]) {
            p2=i;
            break;
        }
    }
    if(p1+p2<m) {
        for (int i = m - 1; i >= 0; i--) {
            if (sa[i]) {
                p1=i;
                break;
            }
        }
        for(int i=m-1;i>=0;i--) {
            if(sb[i]) {
                p2=i;
                break;
            }
        }
    }
    int res=0;
    int num=0;
    for(int i=0,j=m-1;i<m;) {
        if(!sa[i]) {
            i++;
            continue;
        }
        while(j>=0&&!sb[j])j--;
        if(j<0)break;
        if(i+j>=m-1) {
            if(i+j>=m&&sa[i]&&sb[j])num=1;
            int tmp=min(sa[i],sb[j]);
            sa[i]-=tmp;
            sb[j]-=tmp;
            res+=tmp;
            if(!sa[i])i++;
        }
        else i++;
    }

    //cout<<"now_res="<<res<<endl;
    //cout<<"sa: ";
    //for(int i=0;i<m;i++)cout<<sa[i]<<" ";cout<<endl;
    //cout<<"sb: ";
    //for(int i=0;i<m;i++)cout<<sb[i]<<" ";cout<<endl;
    for(int i=0,j=m-1;i<m;i++) {
        if(!sb[i])continue;
        while(j>=0&&!sa[j])j--;
        if(j<0)break;
        if(i+j>=m-1) {
            if(i+j>=m&&sb[i]&&sa[j])num=1;
            int tmp=min(sb[i],sa[j]);
            sb[i]-=tmp;
            sa[j]-=tmp;
            res+=tmp;
        }
    }


    //cout<<"res="<<res<<endl;
    //cout<<"p1="<<p1<<" p2="<<p2<<endl;
    if(num)cout<<res<<endl;
    else {
        if(p1!=m-1&&p2!=m-1)res++;
        if(p1+p2>=m)res--;
        else res=0;
        cout<<res<<endl;
    }
}

signed main() {
    become_faster();
    int T = 1;
    //T=read();
    cin>>T;
    //for(int i=1;i<=100;i++)solve(i);
    while (T--) solve();
    return 0;
}

詳細信息

Test #1:

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

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: 59ms
memory: 5640kb

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

result:

wrong answer 13th numbers differ - expected: '3', found: '2'