100分,剩下的全超时,有大神会优化吗
查看原帖
100分,剩下的全超时,有大神会优化吗
520540
textbook楼主2023/9/19 00:27
#include<bits/stdc++.h>
using namespace std;
const int N=5e4+5;
int n,cnt=1,t,a[N],f[N],u,s=1,ans;
int main(){
	while(cin>>a[cnt]){
		int maxx=0;
		for(int i=1;i<cnt;i++){
			if(a[i]>=a[cnt]){
				if(f[i]>maxx){
					maxx=f[i];
					u=i;
				}
			}
		}
		if(u!=-1||cnt==1) f[cnt]=maxx+1;
		ans=max(ans,f[cnt]);
		cnt++;
	}
	for(int i=1;i<cnt;i++){
		u=-1;
		int minn=100000;
		for(int j=1;j<=s;j++){
			if(a[j]>=a[i]&&a[j]<minn){
				u=j;
				minn=a[j];
			}
		}
		if(u==-1){
			a[++s]=a[i];
		}
		else a[u]=a[i];
	}
	cout<<ans<<endl<<s;
	return 0;
}
2023/9/19 00:27
加载中...