#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
using namespace std;
///~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename H, typename T>
ostream& operator<<(ostream& os, pair<H, T> m){
return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H>
ostream& operator<<(ostream& os, vector<H> V){
os<<"{";
for(int i=0; i<V.size(); i++){
if(i)os<<" ";
os<<V[i];
}
os<<"}";
return os;
}
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
///~~~~~~~~~~~~~~~~~~~~~~~~~
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1e6+5, INF=1e9+5, mod=1e9+7;
vii V;
vi dp;
int par[N];
int solve(int x){
int n=V.size();
for(int i=x; i<=n; i++)dp[i]=0;
for(int i=x; i<n; i++){
if(i+V[i].st<=n)dp[i+V[i].st]=max(dp[i+V[i].st], dp[i]+1);
if(i<n)dp[i+1]=max(dp[i+1], dp[i]);
}
return dp[n];
}
int main(){
//BOOST;
int n;
cin>>n;
V.resize(n);
for(int i=0; i<n; i++){
cin>>V[i].st;
V[i].nd=i+1;
}
sor(V);
rev(V);
dp.resize(n+1);
int l=V[0].st, r=n;
int ans=solve(0);
//deb(V);
//deb(dp);
while(l<r){
int m=(l+r+1)/2;
if(solve(m)+1<ans)r=m-1;
else l=m;
}
cout<<ans<<"\n";
cout<<l<<" ";
for(int i=0; i<l; i++)cout<<V[i].nd<<" ";
cout<<"\n";
for(int i=l; i<n; i++)dp[i]=0;
for(int i=l; i<n; i++){
if(i+V[i].st<n){
if(dp[i+V[i].st]<=dp[i]){
dp[i+V[i].st]=dp[i]+1;
par[i+V[i].st]=i;
}
}
if(i<n-1 && dp[i+1]<dp[i]){
dp[i+1]=dp[i];
par[i+1]=par[i];
}
}
int k=n-1;
for(int i=n-1; i>=l; i--){
if(i==k)cout<<k-par[k]+1<<" ";
cout<<V[i].nd<<" ";
if(i==par[k]){
cout<<"\n";
k=i-1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
2308 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
2536 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
366 ms |
20696 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
500 ms |
27852 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
465 ms |
25744 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |