QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743761#5035. foo~dyj1334460 42ms259812kbC++141.3kb2024-11-13 19:57:472024-11-13 19:57:48

Judging History

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

  • [2024-11-13 19:57:48]
  • 评测
  • 测评结果:0
  • 用时:42ms
  • 内存:259812kb
  • [2024-11-13 19:57:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=6e5+5,K=35;
int n,k,p[N],a[N],dp[N][K],f[N][K],g[N][K],ans,zhan[N],top,pre[N],suf[N];
void solve()
{
	top=0;
	for(int i=1;i<=n;i++)
	{
		while(top&&a[i]>a[zhan[top]])top--;
		pre[i]=zhan[top];zhan[++top]=i;
	}
	top=0;
	for(int i=n;i;i--)
	{
		while(top&&a[i]>a[zhan[top]])top--;
		suf[i]=zhan[top];zhan[++top]=i;
	}
	memset(dp,-0x3f,sizeof(dp)),memset(f,-0x3f,sizeof(f)),memset(g,-0x3f,sizeof(g));
	dp[1][0]=f[1][0]=g[1][0]=1;
	dp[1][1]=f[1][1]=g[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=k;j++)if(pre[i])
		{
			f[i][j]=max(f[i][j],f[pre[i]][j]+1);
			g[i][j]=max(g[i][j],g[pre[i]][j]);
		}
		for(int j=1;j<=k;j++)
		{
			dp[i][j]=max(f[i][j-1],g[i][j-1]);
			f[i+1][j]=max(f[i+1][j],dp[i][j]+1);
			g[i+1][j]=max(g[i+1][j],dp[i][j]+1);
		}
		for(int j=0;j<=k;j++)if(suf[i])
		{
			f[suf[i]][j]=max(f[suf[i]][j],f[i][j]);
			g[suf[i]][j]=max(g[suf[i]][j],g[i][j]+1);
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=k;j++)ans=max(ans,dp[i][j]);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=1;i<=n;i++)if(p[i]==n)
	{
		for(int j=1;j<=n;j++)a[j]=p[(j+i-2)%n+1];
		break;
	}
	solve(),reverse(a+2,a+n+1),solve();
	cout<<ans;
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 24ms
memory: 257568kb

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: 10
Accepted
time: 20ms
memory: 257612kb

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
Wrong Answer
time: 27ms
memory: 259664kb

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:

19

result:

wrong answer 1st words differ - expected: '16', found: '19'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 42ms
memory: 259812kb

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:

46982

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 36ms
memory: 259680kb

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:

1132

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%