QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679361#8057. Best Carry Player 4gaofengWA 91ms9944kbC++232.9kb2024-10-26 17:27:242024-10-26 17:27:24

Judging History

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

  • [2024-10-26 17:27:24]
  • 评测
  • 测评结果:WA
  • 用时:91ms
  • 内存:9944kb
  • [2024-10-26 17:27:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF  = 0x3f3f3f3f;
const ll INFll  = 0x3f3f3f3f3f3f3f3f;
#define endl "\n" 
#define x first
#define y second

//vector<vector<int>>adj(N);

int a[N],b[N];
int aa[N],bb[N];

void solve()
{
    int m;
    cin >> m;
    int suma = 0, sumb = 0;
    for(int i = 0; i < m; i ++) cin >> a[i], suma += a[i];
    for(int j = 0; j < m; j ++) cin >> b[j], sumb += b[j];

    int sum = 0, ans = 0;
   
    // s.push({b[m - 1], m - 1});
    // for(int i = 0; i < m && ans == 0; i ++) {
    //     s.push({b[m - i], m - i});
    //     while(s.size() && s.top().second + i >= m && a[i] && !ans) {
    //         PII t = s.top(); s.pop();
    //         int res = min({a[i], t.first, 1});
    //         a[i] -= res;
    //         b[t.second] -= res;
    //         t.first -= res;
    //         ans += res;
    //         if(t.first) s.push(t);
    //     }
    // }
    // // cout << ans << endl;
    // for(int i = 0; i < m; i ++) cout << a[i] << " "; cout << endl;
    // for(int i = 0; i < m; i ++) cout << b[i] << " "; cout << endl;
    int last = m;
    for(int ii = 0; ii < m; ii ++) {
        if(b[m - ii]) last = m - ii;
        if(a[ii] && b[last]) {
            stack<PII> s;
            int aans = 0;
            for(int i = 0;i < m; i ++) aa[i] = a[i], bb[i] = b[i];
            aa[ii] --;
            bb[last] --;

            for(int i = 0; i < m; i ++) {
                if(m - i - 1 >= 0)s.push({bb[m - i - 1], m - i - 1});
                while(s.size() && s.top().second + i + 1 >= m && aa[i]) {
                    PII t = s.top(); s.pop();
                    int res = min(aa[i], t.first);
                    aa[i] -= res;
                    bb[t.second] -= res;
                    t.first -= res;
                    aans += res;
                    if(t.first) s.push(t);
                }
            }
            aans += aa[m - 1] + bb[m - 1];
            ans = max(ans, aans + 1);
        }
    }

    // while(s.size())s.pop();
    // if(ans) {
    //     for(int i = 0; i < m; i ++) {
    //         if(m - i - 1 >= 0)s.push({b[m - i - 1], m - i - 1});
    //         while(s.size() && s.top().second + i + 1 >= m && a[i]) {
    //             PII t = s.top(); s.pop();
    //             int res = min(a[i], t.first);
    //             a[i] -= res;
    //             b[t.second] -= res;
    //             t.first -= res;
    //             ans += res;
    //             if(t.first) s.push(t);
    //         }
    //     }
    //     ans += a[m - 1] + b[m - 1];
    // }


  

    cout << ans << endl;
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cout << setprecision(11) << fixed;
    int t;t=1;
    cin>>t;
    for(int i=1;i<=t;i++){
        //printf("Case %d: ",i);
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 51ms
memory: 9752kb

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
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ong Answer
time: 91ms
memory: 9628kb

input:

100000
5
119777838 337555280 806504015 458289944 321614229
979242871 431783189 423329635 193632121 7339369
5
189264782 667669243 753322761 861814678 224007583
977519325 104432095 940220826 712094722 903574615
5
977791540 278658984 601762324 633391706 36807634
689562032 997406456 118939957 891425821 ...

output:

1377698543
0
1699584169
2132012702
0
0
0
0
2034726862
0
1476887044
0
1626312268
1068946376
600795101
927483202
0
0
0
1751199962
0
1884010446
0
2014856631
848686688
1069641213
0
1671442806
0
0
1945152013
1885359968
912166748
1600744697
0
0
2032285667
0
1572566306
0
0
1800014687
1966525219
0
115520173...

result:

wrong answer 2nd numbers differ - expected: '2884329841', found: '0'