QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#319252#5035. foo~Harry271820 21ms37192kbC++141.3kb2024-02-02 11:04:302024-02-02 11:04:31

Judging History

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

  • [2024-02-02 11:04:31]
  • 评测
  • 测评结果:0
  • 用时:21ms
  • 内存:37192kb
  • [2024-02-02 11:04:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int f[35][600005],val1[5005][5005],val2[5005][5005],n,k,a[600005],c[600005];
void dp(int k,int l,int r,int pl,int pr)
{
	if(l>r)return;
	int mid=(l+r)>>1,pos=0;
	for(int i=pl;i<=min(mid,pr);i++)
	{
		int now=f[k-1][i-1]+max(val1[i][mid],val2[i][mid]);
		if(now>f[k][mid])f[k][mid]=now,pos=i;
	}
	dp(k,l,mid-1,pl,pos);dp(k,mid+1,r,pos,pr);
}
int solve()
{
	if(k==1)
	{
		int mx=0,res1=0,res2=0;
		for(int i=1;i<=n;i++)if(a[i]>mx)res1++,mx=a[i];
		mx=0;
		for(int i=n;i>=1;i--)if(a[i]>mx)res2++,mx=a[i];
		return max(res1,res2);
	}
	for(int i=1;i<=n;i++)
	{
		int mx=0;
		for(int j=i;j<=n;j++)
		{
			val1[i][j]=val1[i][j-1];
			if(a[j]>mx)mx=a[j],val1[i][j]++;
		}
	}
	for(int i=n;i>=1;i--)
	{
		int mx=0;
		for(int j=i;j>=1;j--)
		{
			val2[j][i]=val2[j+1][i];
			if(a[j]>mx)mx=a[j],val2[j][i]++;
		}
	}
	for(int i=0;i<=k;i++)for(int j=1;j<=n;j++)f[i][j]=-0x3f3f3f3f;f[0][0]=0;
	for(int i=1;i<=k;i++)dp(i,1,n,1,n);
	return f[k][n];
}
int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>k;int p=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		if(c[i]==n)p=i;
	}
	for(int i=1;i<=n;i++)a[i]=c[(i+p-2)%n+1];
	ans=max(ans,solve());
	for(int i=1;i<=n;i++)a[i]=c[(i+p-1)%n+1];
	ans=max(ans,solve());
	cout<<ans;
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

23 6
16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2

output:

20

result:

ok "20"

Test #2:

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

input:

13 6
13 9 3 4 12 6 5 1 8 10 11 7 2

output:

13

result:

ok "13"

Test #3:

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

input:

25 3
25 2 3 19 5 6 7 11 8 10 9 20 4 14 21 1 17 12 13 18 15 22 23 16 24

output:

16

result:

ok "16"

Test #4:

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

input:

25 9
1 11 10 23 9 24 7 8 19 3 5 21 18 12 15 16 17 13 2 20 14 22 4 6 25

output:

23

result:

ok "23"

Test #5:

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

input:

13 2
1 4 2 3 5 6 7 8 9 10 12 11 13

output:

12

result:

ok "12"

Test #6:

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

input:

17 5
4 2 3 6 5 1 7 8 13 16 11 12 9 14 15 10 17

output:

15

result:

ok "15"

Test #7:

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

input:

8 2
1 2 5 6 3 4 7 8

output:

8

result:

ok "8"

Test #8:

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

input:

11 5
3 11 2 10 6 5 1 4 8 7 9

output:

11

result:

ok "11"

Test #9:

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

input:

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

output:

6

result:

ok "6"

Test #10:

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

input:

16 2
15 12 14 9 11 13 1 3 10 8 5 2 16 4 6 7

output:

9

result:

ok "9"

Test #11:

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

input:

6 3
4 1 5 6 2 3

output:

6

result:

ok "6"

Test #12:

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

input:

1 1
1

output:

1

result:

ok "1"

Test #13:

score: -10
Wrong Answer
time: 1ms
memory: 5732kb

input:

16 5
7 14 13 16 10 1 9 11 3 8 2 4 5 15 12 6

output:

13

result:

wrong answer 1st words differ - expected: '14', found: '13'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 0ms
memory: 6388kb

input:

93943 1
87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...

output:

15

result:

wrong answer 1st words differ - expected: '25', found: '15'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 21ms
memory: 37192kb

input:

1992 25
144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...

output:

232

result:

wrong answer 1st words differ - expected: '237', found: '232'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%