QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606556#7067. The Great Walllsj2009WA 1ms4100kbC++201.3kb2024-10-03 10:34:352024-10-03 10:34:36

Judging History

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

  • [2024-10-03 10:34:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4100kb
  • [2024-10-03 10:34:35]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
//#define int long long
#define i128 __int128
#define ll long long
#define ull unsigned long long
#define ld double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
#define pcnt(x) __builtin_popcount(x)
using namespace std;
void file_IO() {
//	system("fc .out .ans");
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
bool M1;
const int N=1e4+5;
int a[N],f[2][N],n;
void solve() {
	scanf("%d",&n);
	rep(i,1,n)
		scanf("%d",&a[i]);
	cl(f[0],-0x3f);
	f[0][0]=0;
	rep(k,1,n) {
		f[k&1][0]=-INF;
		int res1=-INF,res2=-INF;
		rep(i,1,n) {
			chkmax(res1,f[(k&1)^1][i-1]-a[i]);
			chkmax(res2,f[(k&1)^1][i-1]+a[i]);
			f[k&1][i]=max(res1+a[i],res2-a[i]);
		}
		rep(i,1,n)
			chkmax(f[k&1][i],f[k&1][i-1]);
		printf("%d\n",f[k&1][n]);
	}
}
bool M2;
signed main() {
	//file_IO();
	int testcase=1;
	//scanf("%d",&testcase);
	while(testcase--)
		solve();
	fprintf(stderr,"used time = %ldms\n",1000*clock()/CLOCKS_PER_SEC);
	fprintf(stderr,"used memory = %lldMB\n",(&M2-&M1)/1024/1024);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4072kb

input:

5
1 2 1 2 1

output:

1
2
2
1
0

result:

ok 5 lines

Test #3:

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

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: 4084kb

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: 1ms
memory: 4072kb

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: 1ms
memory: 4100kb

input:

1
79932

output:

0

result:

ok single line: '0'

Test #7:

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

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:

8
17
26
35
44
53
62
71
80
89
98
107
116
125
134
143
152
161
170
179
188
197
206
215
224
233
242
251
260
269
278
287
296
305
314
322
330
338
346
354
362
370
378
386
394
402
410
418
426
434
442
450
458
466
474
482
490
498
506
513
520
527
534
541
548
555
562
569
576
583
590
597
604
610
616
622
628
634
...

result:

wrong answer 1st lines differ - expected: '9', found: '8'