QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#74821#5035. foo~Sljeuo0 32ms96548kbC++141.5kb2023-02-04 10:11:012023-02-04 10:11:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-04 10:11:02]
  • 评测
  • 测评结果:0
  • 用时:32ms
  • 内存:96548kb
  • [2023-02-04 10:11:01]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int INF=2100000000,N=6e5+5,K=30+5;
int n,k;
int f[K][N],lasf[N],lasb[N],st[N];
int calc(int p[],int i,int &tp)
{
	while(tp&&p[i]>p[st[tp]])
		--tp;
	st[++tp]=i;
	return st[tp-1];
}
int a[N];
int work(int p[])
{
	memset(f,0,sizeof(f));
	for(int i=1,tp=0; i<=n; ++i)
		lasf[i]=calc(p,i,tp);
	for(int i=n,tp=0; i>=1; --i)
		lasb[i]=calc(p,i,tp);
	for(int i=1; i<=k; ++i)
	{
		for(int j=1; j<=n; ++j)
			a[j]=f[i-1][j-1]+1;
		for(int j=1; j<=n; ++j)
			a[j]=max(a[j],a[j-1]);
		for(int j=1; j<=n; ++j)
			if(lasf[j])
				a[j]=max(a[j],a[lasf[j]]+1);
		for(int j=1; j<=n; ++j)
			f[i][j]=max(f[i][j],a[j]);

		for(int j=1; j<=n; ++j)
			a[j]=f[i-1][j-1]+1;
		for(int j=1; j<=n; ++j)
			if(lasb[j])
				a[lasb[j]]=max(a[lasb[j]],a[j]+1);
		for(int j=1; j<=n; ++j)
			a[j]=max(a[j],a[j-1]);
		for(int j=1; j<=n; ++j)
			f[i][j]=max(f[i][j],a[j]);	
	}
	for(int i=1; i<=k; ++i)
	{
		for(int j=1; j<=n; ++j)
			cout<<f[i][j]<<' ';
		cout<<endl;
	}
	return f[k][n];
}
int p[N<<1],x[N];
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>k;
	int pn=0;
	for(int i=1; i<=n; ++i)
	{
		scanf("%d",&p[i]),p[n+i]=p[i];
		if(p[i]==n)
			pn=i;
	}
	for(int i=pn+1,cnt=1; cnt<=n; ++cnt,++i)
		x[cnt]=p[i];
	int ans=work(x);
	for(int i=pn+n-1,cnt=1; cnt<=n; ++cnt,--i)
		x[cnt]=p[i];
	printf("%d\n",max(ans,work(x)));		
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 20ms
memory: 93976kb

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:

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

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 32ms
memory: 96548kb

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:

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

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 19ms
memory: 96136kb

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:

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

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%