Submission #911496

# Submission time Handle Problem Language Result Execution time Memory
911496 2024-01-19T02:22:23 Z MilosMilutinovic Teams (CEOI11_tea) C++14
80 / 100
269 ms 34680 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],lst[1000005];
pii a[1000005];

int solve(int x){
	for(int i=0;i<=n;i++){
		dp[i]=(int)-1e9;
		prv[i]=0;
	}
	dp[0]=lst[0]=0;
	for(int i=1;i<=n;i++){
		lst[i]=lst[i-1];
		if(a[i].fi>i) continue;
		int p=lst[i-a[i].fi];
		if(p>=max(0,i-x)){
			dp[i]=dp[p]+1;
			prv[i]=p;
			lst[i]=i;
		}
	}
	return dp[n];
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i].fi=readint(),a[i].se=i;
	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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9072 KB Output is correct
2 Correct 17 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 9188 KB Output is correct
2 Correct 16 ms 9052 KB Output is correct
3 Correct 25 ms 9556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 24040 KB Output is correct
2 Correct 175 ms 26360 KB Output is correct
3 Correct 174 ms 28552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 26704 KB Output is correct
2 Correct 258 ms 31764 KB Output is correct
3 Correct 231 ms 29652 KB Output is correct
4 Correct 215 ms 30532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 26704 KB Output is correct
2 Correct 125 ms 34680 KB Output is correct
3 Correct 224 ms 30640 KB Output is correct
4 Correct 269 ms 32844 KB Output is correct