Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
52407 chy很帅 木板游戏 C++ 运行超时 60 2000 MS 6100 KB 1129 2022-07-19 12:08:39

Tests(12/20):


#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn=5e5+10; const int inf=1e9+7; int n,ans,dp[maxn]; struct node { int l,r; } s[maxn]; inline int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')w=-1; ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline bool cmp(node a,node b) { if(a.r-a.l==b.r-b.l) return a.l<b.l; return a.r-a.l>b.r-b.l; } signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n=read(); for(int i=1; i<=n; ++i) { s[i].l=read(),s[i].r=read(); } sort(s+1,s+n+1,cmp); for(int i=1; i<=n; ++i) dp[i]=1; for(int i=n; i>1; --i) { for(int j=i-1; j>0; --j) { if(s[j].l<=s[i].l&&s[j].r>=s[i].r) { dp[j]=max(dp[j],dp[i]+1); } } } for(int i=1; i<=n; ++i) ans=max(ans,dp[i]); printf("%d\n",ans); return 0; } /* 6 4 7 2 5 8 9 1 8 2 6 3 4 */


测评信息: