QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679368#8057. Best Carry Player 4gaofengTL 492ms9976kbC++233.0kb2024-10-26 17:28:072024-10-26 17:28:08

Judging History

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

  • [2024-10-26 17:28:08]
  • 评测
  • 测评结果:TL
  • 用时:492ms
  • 内存:9976kb
  • [2024-10-26 17:28:07]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
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: 1ms
memory: 9732kb

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: 53ms
memory: 9732kb

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 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 0
Accepted
time: 101ms
memory: 9976kb

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
2884329841
1699584169
2132012702
2531472710
2754014935
2585135038
2577893498
2034726862
2303377730
1476887044
2618960687
1626312268
1068946376
600795101
927483202
2151016849
2256729729
2291627593
1751199962
2412405837
1884010446
2553701265
2014856631
848686688
1069641213
2412585811
167144...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 120ms
memory: 9736kb

input:

50000
10
18209490 798013131 762297136 184230300 323229686 771738936 850827138 201740028 818693101 945688434
101715068 966337103 309026840 698679951 666034197 810411289 841033024 740762082 484989962 19640395
10
608177485 700383507 317699894 982085408 908794603 92931066 880099629 965892642 576147264 9...

output:

5341540062
3811346608
3280168940
4222050470
4327730826
4389011469
5146997799
3799138189
4028437054
3650616128
4267213780
5220650313
3272450503
3560399774
5130261345
4384881302
4681302604
5415587476
2376088103
3344427945
3701410392
3434767065
4969556102
4474318648
4751503347
3701971157
5053000969
397...

result:

ok 50000 numbers

Test #6:

score: 0
Accepted
time: 492ms
memory: 9920kb

input:

5000
100
405163017 116989072 685766112 551211950 862199350 861827829 564364529 922314891 241721254 160976656 891732149 553649064 445152950 859742462 235262967 648909226 943054063 484936253 414150625 995061073 662853643 367723189 348457562 591856009 309322986 450413840 159926452 24214846 79239852 397...

output:

44348367445
47318596151
43893435579
49579921753
48669603728
45875221434
49002488594
53587378598
52208712766
49588253701
50196256163
49596309746
48141429048
49878478140
49036091100
46395088830
42672527744
41761915575
47439675311
47743457344
44672635972
50006245688
49397345810
46906644735
49589049416
...

result:

ok 5000 numbers

Test #7:

score: -100
Time Limit Exceeded

input:

500
1000
193550719 323493453 457420643 784509248 590688212 53858799 864840302 864699978 833248388 388148011 424847622 153776183 812936693 826657538 546327769 8986082 692715231 409800344 238099504 373879563 776749117 721714043 87525288 267321580 716697878 959194006 945266703 700945389 403532515 62661...

output:


result: