#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int INF = 1e9;
const int MAXN = (int) 1e6;
pair <int, int> arr[MAXN + 1];
pair <int, int> best[MAXN + 1];
int dp[MAXN + 1], from[MAXN + 1];
int last[MAXN + 1];
inline int check(int n, int len) {
for(int i = 1; i <= n; i++) {
if(i - arr[i].first < 0) {
dp[i] = -INF;
}
else {
if(i - last[i - arr[i].first] <= len) {
dp[i] = dp[last[i - arr[i].first]] + 1;
from[i] = last[i - arr[i].first];
}
else {
dp[i] = -INF;
}
}
last[i] = last[i - 1];
if(dp[i] > -INF) {
last[i] = i;
}
}
return dp[n];
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for(i = 1; i <= n; i++) {
cin >> arr[i].first;
arr[i].second = i;
}
sort(arr + 1, arr + n + 1);
int ans = check(n, n);
int res = arr[n].first - 1;
for(int step = 1 << 20; step; step >>= 1) {
if(res + step <= n && check(n, res + step) < ans) {
res += step;
}
}
check(n, res + 1);
cout << ans << "\n";
int pos = n;
while(pos > 0) {
cout << pos - from[pos] << " ";
for(i = from[pos] + 1; i <= pos; i++) {
cout << arr[i].second << " ";
}
cout << "\n";
pos = from[pos];
}
//cin.close();
//cout.close();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2296 KB |
Output is correct |
2 |
Correct |
23 ms |
2360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
2552 KB |
Output is correct |
2 |
Correct |
21 ms |
2268 KB |
Output is correct |
3 |
Correct |
27 ms |
2604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
20200 KB |
Output is correct |
2 |
Correct |
234 ms |
22364 KB |
Output is correct |
3 |
Correct |
240 ms |
24312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
320 ms |
26488 KB |
Output is correct |
2 |
Correct |
294 ms |
31608 KB |
Output is correct |
3 |
Correct |
326 ms |
29688 KB |
Output is correct |
4 |
Correct |
298 ms |
28408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
25212 KB |
Output is correct |
2 |
Correct |
200 ms |
30584 KB |
Output is correct |
3 |
Correct |
317 ms |
30704 KB |
Output is correct |
4 |
Correct |
345 ms |
32376 KB |
Output is correct |