QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569395#8057. Best Carry Player 4gates_orzWA 110ms5672kbC++172.4kb2024-09-16 22:35:362024-09-16 22:35:38

Judging History

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

  • [2024-09-16 22:35:38]
  • 评测
  • 测评结果:WA
  • 用时:110ms
  • 内存:5672kb
  • [2024-09-16 22:35:36]
  • 提交

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 - 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;
    //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;) {
        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;
    if(num)cout<<res<<endl;
    else {

        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: 5636kb

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: 110ms
memory: 5672kb

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

result:

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