QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733433#7067. The Great WallYurilyWA 1ms3704kbC++201.9kb2024-11-10 18:52:452024-11-10 18:52:46

Judging History

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

  • [2024-11-10 18:52:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3704kb
  • [2024-11-10 18:52:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAX=1e4+5;
long long f[MAX][2][3][2];
int a[MAX],n,k;
long long ans[MAX];
int main(){
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin>>n;
    k=n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    
    int mins=1e9,maxs=-1e9;
    for(int i=1;i<=n;++i){
        mins=min(mins,a[i]);
        maxs=max(maxs,a[i]);
        f[i][0][0][0]=maxs-mins;
        f[i][0][1][1]=f[i][0][1][0]=maxs;
        f[i][0][2][1]=mins,f[i][0][2][0]=-mins;
    }
    ans[1]=f[n][0][0][0];

    int pre=0;
    for(int j=2;j<=k;++j){
        int cur=(pre^1);
        for(int i=0;i<=n;++i)
            f[i][cur][0][0]=f[i][cur][1][0]=f[i][cur][2][0]=-1e13;

        for(int i=j;i<=n;++i){
            f[i][cur][0][0]=max(f[i-1][pre][0][0],max(f[i-1][cur][1][0]-a[i],f[i-1][cur][2][0]+a[i]));

            if(a[i]>f[i-1][cur][1][1])
                f[i][cur][1][0]=f[i-1][cur][1][0]-f[i-1][cur][1][1]+a[i],f[i][cur][1][1]=a[i];
            else
                f[i][cur][1][0]=f[i-1][cur][1][0],f[i][cur][1][1]=f[i-1][cur][1][1];
            if(f[i-1][pre][0][0]+a[i]>f[i][cur][1][0]){
                f[i][cur][1][1]=a[i];
                f[i][cur][1][0]=f[i-1][pre][0][0]+a[i];
            }

            if(a[i]<f[i-1][cur][2][1])
                f[i][cur][2][0]=f[i-1][cur][2][0]+f[i-1][cur][2][1]-a[i],f[i][cur][2][1]=a[i];
            else
                f[i][cur][2][0]=f[i-1][cur][2][0],f[i][cur][2][1]=f[i-1][cur][2][1];
            if(f[i-1][pre][0][0]-a[i]>f[i][cur][2][0]){
                f[i][cur][2][1]=a[i];
                f[i][cur][2][0]=f[i-1][pre][0][0]-a[i];
            }
        }
        ans[j]=f[n][cur][0][0];
        pre=cur;
    }

    for(int i=1;i<=k;++i){
        cout<<ans[i]<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2 3 4 5

output:

4
3
2
1
0

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

5
1 2 1 2 1

output:

1
2
2
1
0

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

6
1 1 4 5 1 4

output:

4
7
7
7
4
0

result:

ok 6 lines

Test #4:

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

input:

6
1 9 1 9 8 1

output:

8
16
23
16
8
0

result:

ok 6 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

12
1 1 4 5 1 4 1 9 1 9 8 1

output:

8
16
23
27
30
30
30
27
23
16
8
0

result:

ok 12 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

1
79932

output:

0

result:

ok single line: '0'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3704kb

input:

500
2 4 2 9 3 1 9 1 2 9 9 9 2 3 8 6 6 5 6 4 9 9 6 4 4 3 1 3 4 6 9 7 1 8 3 10 1 1 1 1 2 2 8 4 4 1 9 1 3 7 5 10 1 3 2 1 3 4 8 4 2 2 2 3 10 8 8 8 6 1 3 5 10 10 6 7 9 7 3 2 5 5 4 10 2 2 8 6 10 8 8 10 4 1 9 8 1 7 10 10 1 1 4 3 8 7 10 3 3 7 3 3 4 1 1 4 1 7 8 2 8 9 6 4 6 6 7 1 3 9 4 4 4 10 8 5 6 7 8 6 6 5 ...

output:

9
18
27
36
45
54
63
72
81
90
99
108
117
125
134
143
151
159
167
176
184
192
201
210
218
226
234
242
251
260
268
277
286
294
303
309
317
325
332
340
346
354
361
370
378
385
393
399
407
415
422
430
439
444
452
458
466
473
480
487
493
500
507
514
521
527
534
540
546
552
558
564
570
576
582
588
595
601
...

result:

wrong answer 14th lines differ - expected: '126', found: '125'