QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#256394#4591. Maxdifficent Groupjiayi_koWA 17ms6968kbC++142.2kb2023-11-18 19:07:012023-11-18 19:07:02

Judging History

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

  • [2023-11-18 19:07:02]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:6968kb
  • [2023-11-18 19:07:01]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> a(100005);
int main(){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    ll sumbig=0, sumsmol=0;
    vector<ll> bigstart(n+5), bigend(n+5), smolstart(n+5), smolend(n+5);
    for(int i=0; i<n; i++){
        if(sumbig + a[i] >= 0){
            sumbig+=a[i];
        }
        else{
            sumbig=0;
        }
        if(sumsmol + a[i] <= 0){
            sumsmol+=a[i];
        }
        else{
            sumsmol=0;
        }
        
        if(i > 0){
            bigend[i]=max(bigend[i-1], sumbig);
            smolend[i]=min(smolend[i-1], sumsmol);
        }
        else{
            bigend[i]=sumbig;
            smolend[i]=sumsmol;
        }
    }
    sumsmol=sumbig=0;
    for(int i=n-1; i>=0; i--){
        if(sumbig + a[i] >= 0){
            sumbig+=a[i];
        }
        else{
            sumbig=0;
        }
        if(sumsmol + a[i] <= 0){
            sumsmol+=a[i];
        }
        else{
            sumsmol=0;
        }

        if(i<n-1){
            bigstart[i]=max(bigstart[i+1], sumbig);
            smolstart[i]=min(smolstart[i+1], sumsmol);
        }
        else{
            bigstart[i]=sumbig;
            smolstart[i]=sumsmol;
        }
    }
    bool allpos=true, allneg=true;
    for(int i=0; i<n; i++){
        if(a[i] < 0){
            allpos=false;
            break;
        }
    }
    if(allpos){
        for(int i=0; i<n; i++){
            smolend[i]=a[0];
            smolstart[i]=a[n-1];
        }
    }
    for(int i=0; i<n; i++){
        if(a[i] > 0){
            allneg=false;
            break;
        }
    }
    if(allneg){
        for(int i=0; i<n; i++){
            bigend[i]=a[0];
            bigstart[i]=a[n-1];
        }
    }
    
    ll ans=0;
    for(int i=0; i<n; i++){
        // cout<<"now "<<i<<": \n";
        // cout<<bigstart[i]<<" "<<bigend[i]<<"\n";
        // cout<<smolstart[i]<<" "<<smolend[i]<<"\n";
        if(i<n-1) ans=max(ans, abs(bigend[i]-smolstart[i+1]));
        if(i<n-1) ans=max(ans, abs(smolend[i]-bigstart[i+1]));
    }
    cout<<ans<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
100 -30 -20 50

output:

150

result:

ok single line: '150'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

5
12 7 4 32 9

output:

46

result:

ok single line: '46'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3716kb

input:

6
-5 10 -5 45 -20 15

output:

70

result:

ok single line: '70'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

14
1 5 3 4 2 -4 -2 -6 -5 6 4 2 3 9

output:

41

result:

ok single line: '41'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3716kb

input:

2
0 -900000

output:

900000

result:

ok single line: '900000'

Test #6:

score: 0
Accepted
time: 7ms
memory: 5632kb

input:

59394
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 8ms
memory: 5916kb

input:

63744
-1 0 1 1 0 0 1 -1 -1 -1 -1 -1 1 1 1 -1 0 0 1 1 1 -1 1 -1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 -1 1 1 1 -1 1 -1 0 0 -1 -1 1 1 0 0 0 1 0 -1 -1 0 0 0 1 -1 0 1 0 0 1 -1 -1 0 0 -1 -1 1 0 1 0 1 0 -1 0 -1 1 1 -1 1 1 -1 1 -1 1 0 0 -1 1 1 0 0 -1 0 0 1 0 0 1 -1 1 0 1 0 -1 0 0 1 0 0 -1 0 0 0 -1 0 0 1 -1 -...

output:

475

result:

ok single line: '475'

Test #8:

score: 0
Accepted
time: 7ms
memory: 6516kb

input:

87255
4 -9 3 -3 -2 -2 3 10 -7 -10 -5 5 -9 -7 1 -1 10 0 -1 1 10 -9 -8 8 5 -8 2 -3 -7 7 -5 -3 3 -2 5 -1 -5 6 -2 8 3 0 -6 5 -10 5 0 -8 -3 -1 -7 -3 0 7 -4 5 -1 -5 -9 -2 8 7 6 -2 6 9 -2 6 10 3 10 -10 4 5 -9 0 -10 -9 -10 6 9 -5 -3 -7 -2 -4 6 4 7 -4 4 2 -8 -2 -4 3 2 -9 -4 9 3 8 -5 -1 8 -10 8 -3 -6 7 -1 8 -...

output:

5780

result:

ok single line: '5780'

Test #9:

score: 0
Accepted
time: 2ms
memory: 4620kb

input:

22859
123270 568778 416102 510776 597790 125263 860375 89550 16897 909046 124583 592535 32050 175429 993750 899188 863104 608753 724971 728319 82786 733737 923128 266621 57189 518044 556356 756193 408537 94718 998619 206034 125763 649241 204930 474150 57466 358193 153011 416494 753281 480726 927554 ...

output:

11402652338

result:

ok single line: '11402652338'

Test #10:

score: 0
Accepted
time: 5ms
memory: 4888kb

input:

33834
-514303 -172893 -206523 -8184 -343624 -208669 -690452 -17023 -342571 -830835 -999032 -533750 -822347 -62447 -85968 -172653 -485779 -40414 -37219 -564266 -427415 -565431 -197676 -911379 -238653 -602443 -410483 -122721 -921143 -764784 -355380 -23053 -510189 -547702 -165836 -672416 -12018 -966618...

output:

16851470332

result:

ok single line: '16851470332'

Test #11:

score: 0
Accepted
time: 8ms
memory: 5200kb

input:

38275
-999930 -999875 -999861 -999804 -999784 -999669 -999500 -999492 -999437 -999435 -999368 -999324 -999180 -999143 -999117 -999090 -999085 -999026 -998991 -998956 -998853 -998850 -998832 -998603 -998594 -998572 -998559 -998550 -998506 -998390 -998277 -998258 -998220 -998135 -998087 -997967 -99785...

output:

19123721387

result:

ok single line: '19123721387'

Test #12:

score: 0
Accepted
time: 8ms
memory: 5156kb

input:

37238
999909 999833 999825 999777 999746 999734 999700 999678 999636 999622 999616 999213 999117 999095 998985 998963 998939 998861 998771 998769 998739 998677 998636 998634 998531 998275 998224 998146 998046 997992 997955 997788 997735 997647 997629 997628 997490 997456 997230 997193 997118 996935 ...

output:

18615206654

result:

ok single line: '18615206654'

Test #13:

score: 0
Accepted
time: 9ms
memory: 5208kb

input:

43149
-140201 -501803 656742 -329686 -795682 -699585 891458 639773 -265403 -322470 587438 -291944 981542 -514447 -146704 158657 308640 -720314 -593447 93738 -837311 -528874 -298652 643385 -665241 124247 -263996 -251752 -777850 814558 134614 498228 23865 628783 856530 -100188 350276 685071 -635465 54...

output:

179476167

result:

ok single line: '179476167'

Test #14:

score: -100
Wrong Answer
time: 17ms
memory: 6968kb

input:

100000
-157175 -347083 -932037 -545196 -659616 600072 -286127 -201837 -997799 -12057 -921128 -6769 -754129 -681225 -136294 -187918 -42011 -568716 -816662 -239977 -417282 -319395 -751876 -674830 -570340 -724210 -422603 -961907 -699371 -249593 -881886 -260367 -873171 -830607 -733352 -533789 -980129 -7...

output:

45189752425

result:

wrong answer 1st lines differ - expected: '45189595250', found: '45189752425'