QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679306#8057. Best Carry Player 4lqh2024#WA 52ms5568kbC++201.9kb2024-10-26 17:20:012024-10-26 17:20:02

Judging History

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

  • [2024-10-26 17:20:02]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:5568kb
  • [2024-10-26 17:20:01]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std ;
const int maxn = 5e5+10 ;
int a[maxn],b[maxn] ;
int m ;
void solve(){
    cin >> m ;
    for(int i = 0 ; i < m ; i++)
        cin >> a[i] ;
    for(int i = 0 ; i < m ; i++)
        cin >> b[i] ;
    int suma = accumulate(a, a + m, 0ll);
    int sumb = accumulate(b, b + m, 0ll);
    int ans = 0 ;

    set<int> s;

    int mn = numeric_limits<int>::max(), ida = -1, idb = -1;

    for (int i = 0; i < m; i++) {
        if (a[i]) s.insert(i);
    }
    for (int i = 0; i < m; i++) {
        if (b[i]) {
            auto it = s.lower_bound(m - i);
            if (it != s.end()) {
                if (mn > *it + i) {
                    mn = *it + i;
                    ida = *it, idb = i;
                }
            }
        }
    }
    if (mn == numeric_limits<int>::max()) {
        cout << "0\n";
        return;
    }
    a[ida]-- ; b[idb]-- ;
    ans++ ;
    for(int i = 0 ; i < m ; i++)
    {
        int j = m-i-1 ;
        if(a[i]>=b[j]){
            a[i]-=b[j] ;
            ans+=b[j] ;
            b[j] = 0 ;
        }
        else{
            ans+=a[i] ;
            b[j]-=a[i] ;
            a[i] = 0 ;
        }
    }
    // cout<<"???"<<ans<<"\n" ;
    int mx = max(suma, sumb);
    if (suma < mx) {
        a[0] += mx - suma;
    } if (sumb < mx) {
        b[0] += mx - sumb;
    }
    for (int i = 0, j = m - 1; j >= 0; ) {
        while (i < m && a[i] == 0) i++;
        while (j >= 0 && b[j] == 0) j--;
        while (i < m && i + j < m - 1) i++;
        if (i == m || j == -1) break;
        int tmp = min(a[i], b[j]);
        a[i] -= tmp, b[j] -= tmp;
        ans += tmp;
    }

    cout << ans << "\n";
}
signed main(){
    ios::sync_with_stdio(false) ;
    cin.tie(0) ; cout.tie(0) ;
    int t ; cin >> t ; 
    while(t--)solve() ;
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 52ms
memory: 5568kb

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
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
3
3
1
4
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
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
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 32nd numbers differ - expected: '5', found: '4'