답안 #911495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
911495 2024-01-19T02:13:36 Z MilosMilutinovic Teams (CEOI11_tea) C++14
70 / 100
2500 ms 33008 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,dp[1000005],prv[1000005];
pii a[1000005];

namespace seg{
	int lim;
	pii st[4000005];
	void init(){
		for(lim=1;lim<=n+1;lim*=2);
	}
	void modify(int p,pii v){
		for(st[p+=lim]=v;p>1;p>>=1) st[p>>1]=max(st[p],st[p^1]);
	}
	pii query(int l,int r){
		pii ret=mp(-1e9,-1);
		for(l+=lim,r+=lim+1;l<r;l>>=1,r>>=1){
			if(l&1) ret=max(ret,st[l++]);
			if(r&1) ret=max(ret,st[--r]);
		}
		return ret;
	}
};

int solve(int x){
	for(int i=0;i<=n;i++){
		dp[i]=(int)-1e9;
		prv[i]=0;
	}
	dp[0]=0;
	for(int i=0;i<=n;i++) seg::modify(i,mp(dp[i],i));
	for(int i=1;i<=n;i++){
		if(a[i].fi>i) continue;
		pii v=seg::query(max(0,i-x),i-a[i].fi);
		dp[i]=v.fi+1; 
		prv[i]=v.se;
		seg::modify(i,mp(dp[i],i));
	}
	return dp[n];
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i].fi=readint(),a[i].se=i;
	seg::init();
	sort(a+1,a+n+1);
	int mx=solve(n);
	int l=a[n].fi,r=n,f=n;
	while(l<=r){
		int mid=(l+r)/2;
		if(solve(mid)==mx) f=mid,r=mid-1;
		else l=mid+1;
	}
	solve(f);
	printf("%d\n",mx);
	int p=n;
	while(p>0){
		printf("%d ",p-prv[p]);
		for(int i=prv[p]+1;i<=p;i++) printf("%d ",a[i].se);
		printf("\n");
		p=prv[p];
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6488 KB Output is correct
2 Correct 15 ms 6492 KB Output is correct
3 Correct 15 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 6488 KB Output is correct
2 Correct 14 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 13124 KB Output is correct
2 Correct 263 ms 13392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 354 ms 13636 KB Output is correct
2 Correct 231 ms 13448 KB Output is correct
3 Correct 352 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2537 ms 29780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2506 ms 33008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2550 ms 32964 KB Time limit exceeded
2 Halted 0 ms 0 KB -