#include <algorithm>
#include <iostream>
#include <memory.h>
#include <bitset>
using namespace std;
const int NMAX = 1e5 + 1e2;
const int INF = 1e9;
int n;
int dp[NMAX];
int pr[NMAX], opt[NMAX], par[NMAX];
pair < int, int > a[NMAX];
bitset < NMAX > ok;
bool check(int x) {
ok = 0;
ok[0] = 1;
for(int i = 1; i <= n; i++) {
if(i - a[i].first < 0) {
dp[i] = -INF;
} else {
dp[i] = pr[i - a[i].first] + 1;
if(opt[i - a[i].first] >= i - x) {
ok[i] = 1;
par[i] = opt[i - a[i].first];
}
}
pr[i] = pr[i - 1];
opt[i] = opt[i - 1];
if(ok[i] == 1 && pr[i] <= dp[i]) {
opt[i] = i;
pr[i] = dp[i];
}
}
return (bool)ok[n];
}
void printsol(int x) {
if(x == 0)
return;
int p1 = par[x];
printsol(p1);
cout << x - p1 << ' ';
for(int i = p1 + 1; i <= x; i++)
cout << a[i].second << ' ';
cout << '\n';
}
void bin_src(int &le, int &ri) {
while(le != ri) {
int mid = (le + ri) / 2;
if(check(mid) == false)
le = mid + 1;
else
ri = mid;
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + n + 1);
int le = 1;
int ri = n;
bin_src(le, ri);
check(le);
cout << dp[n] << '\n';
printsol(n);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
544 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
2 ms |
656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
696 KB |
Output is correct |
2 |
Correct |
3 ms |
696 KB |
Output is correct |
3 |
Correct |
3 ms |
700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
832 KB |
Output is correct |
2 |
Correct |
5 ms |
832 KB |
Output is correct |
3 |
Correct |
5 ms |
904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
904 KB |
Output is correct |
2 |
Correct |
5 ms |
944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
3160 KB |
Output is correct |
2 |
Correct |
33 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
3652 KB |
Output is correct |
2 |
Correct |
30 ms |
3652 KB |
Output is correct |
3 |
Correct |
41 ms |
4404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
647 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
752 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
47 ms |
263168 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |