QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593852#6968. 守卫_TLEer_100 ✓48ms101220kbC++14616b2024-09-27 16:26:572024-09-27 16:26:58

Judging History

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

  • [2024-09-27 16:26:58]
  • 评测
  • 测评结果:100
  • 用时:48ms
  • 内存:101220kb
  • [2024-09-27 16:26:57]
  • 提交

answer

#include<bits/stdc++.h>
#define eps 1e-7
using namespace std;
int dp[5010][5010],n,h[5010],ans;
#define seek(p,a,b) ((double)(1)*(h[p]-h[a])/(p-a)>(double)(1)*(h[p]-h[b])/(p-b))
signed main(){
    ios::sync_with_stdio(false);
    cin.tie();cout.tie();
    cin>>n;
    for(int i=1;i<=n;i++)cin>>h[i];
	for(int i=1;i<=n;i++){
		dp[i][i]=1;ans^=1;
		int sigm=1,lst=0;
		for(int j=i-1;j>=1;j--){
			if(!lst)lst=j;
			else if(seek(i,lst,j))
				sigm+=min(dp[j+1][lst],dp[j+1][lst-1]),lst=j;
			dp[j][i]=sigm+min(dp[j][lst],dp[j][lst-1]);
			ans^=dp[j][i];
		}
	}
	cout<<ans<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 5720kb

input:

20
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 632272582 856183512 735834478 604710445 475814705 581607279 875443850 967283125 469235857 680058587

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3620kb

input:

19
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 11234478 632272582 856183512 735834478 604710445 475814705 581607279 875443850 967283125 469235857

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3704kb

input:

20
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 632272582 856183512 735834478 604710445 475814705 581607279 875443850 967283125 469235857 680058587

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 10
Accepted
time: 0ms
memory: 12424kb

input:

499
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 90909090 2 76923076 2 66666666 8 58823529 5 52631578 5 47619047 9 43478260 10 40000000 5 37037037 7 34482758 7 32258064 7 30303030 5 28571428 6 27027027 5 25641025 4 24390243 3 23255813 8 22222222 7 21276595 6 20408163 10 19607843 5 1...

output:

119

result:

ok 1 number(s): "119"

Test #5:

score: 10
Accepted
time: 3ms
memory: 14252kb

input:

500
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 90909090 2 76923076 2 66666666 8 58823529 5 52631578 5 47619047 9 43478260 10 40000000 5 37037037 7 34482758 7 32258064 7 30303030 5 28571428 6 27027027 5 25641025 4 24390243 3 23255813 8 22222222 7 21276595 6 20408163 10 19607843 5 1...

output:

17

result:

ok 1 number(s): "17"

Test #6:

score: 10
Accepted
time: 3ms
memory: 14172kb

input:

499
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 90909090 2 76923076 2 66666666 8 58823529 5 52631578 5 47619047 9 43478260 10 40000000 5 37037037 7 34482758 7 32258064 7 30303030 5 28571428 6 27027027 5 25641025 4 24390243 3 23255813 8 22222222 7 21276595 6 20408163 10 19607843 5 1...

output:

119

result:

ok 1 number(s): "119"

Test #7:

score: 10
Accepted
time: 0ms
memory: 14060kb

input:

500
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 90909090 2 76923076 2 66666666 8 58823529 5 52631578 5 47619047 9 43478260 10 40000000 5 37037037 7 34482758 7 32258064 7 30303030 5 28571428 6 27027027 5 25641025 4 24390243 3 23255813 8 22222222 7 21276595 6 20408163 10 19607843 5 1...

output:

17

result:

ok 1 number(s): "17"

Test #8:

score: 10
Accepted
time: 48ms
memory: 73200kb

input:

4999
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 90909090 2 76923076 2 66666666 8 58823529 5 52631578 5 47619047 9 43478260 10 40000000 5 37037037 7 34482758 7 32258064 7 30303030 5 28571428 6 27027027 5 25641025 4 24390243 3 23255813 8 22222222 7 21276595 6 20408163 10 19607843 5 ...

output:

71

result:

ok 1 number(s): "71"

Test #9:

score: 10
Accepted
time: 39ms
memory: 100628kb

input:

5000
1000000000 6 333333333 8 200000000 10 142857142 4 111111111 8 90909090 2 76923076 2 66666666 8 58823529 5 52631578 5 47619047 9 43478260 10 40000000 5 37037037 7 34482758 7 32258064 7 30303030 5 28571428 6 27027027 5 25641025 4 24390243 3 23255813 8 22222222 7 21276595 6 20408163 10 19607843 5 ...

output:

16

result:

ok 1 number(s): "16"

Test #10:

score: 10
Accepted
time: 36ms
memory: 101220kb

input:

4999
1000000000 3 333333333 7 200000000 6 142857142 5 111111111 1 90909090 4 76923076 6 66666666 9 58823529 8 52631578 7 47619047 9 43478260 8 40000000 10 37037037 9 34482758 4 32258064 3 30303030 5 28571428 5 27027027 5 25641025 6 24390243 9 23255813 10 22222222 6 21276595 3 20408163 10 19607843 8 ...

output:

370

result:

ok 1 number(s): "370"

Extra Test:

score: 0
Extra Test Passed