이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define f first
#define s second
#define mp make_pair
#define sz(x) int(x.size())
using pi = pair<int, int>;
template<class T> using V = vector<T>;
using vi = V<int>;
const int INF = int(1e9) + 10;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
V<int> A(N); for(auto& x : A) cin >> x;
V<pi> B(N); for(int i = 0; i < N; i++) B[i] = mp(A[i], i);
sort(begin(B), end(B));
V<int> dp, par, lst;
auto check = [&](int W) {
dp = V<int>(N+1, -INF), par = V<int>(N+1, -INF), lst = V<int>(N+1, -1);
dp[0] = 0, par[0] = -1, lst[0] = 0;
for(int i = 1; i <= N; i++) {
int R = max(-1, i - B[i-1].first);
if (R < 0) dp[i] = -INF;
else {
int prv = lst[R];
if ((i - prv) > W) dp[i] = -INF;
else dp[i] = dp[prv] + 1, par[i] = prv;
}
if (dp[i] == -INF || dp[i] < dp[lst[i-1]]) lst[i] = lst[i-1];
else lst[i] = i;
// cout << i << " " << dp[i] << endl;
}
return dp[N];
};
int most = check(N + 1);
int lo = *max_element(begin(A), end(A)), hi = N + 1;
while(lo < hi) {
int mid = (lo + hi) / 2;
// cout << lo << " < " << mid << " < " << hi << endl;
if (check(mid) == most) hi = mid;
else lo = mid + 1;
// cout << dp[N - 1] << endl;
}
// cout << "ANS: " << lo << endl;
check(lo);
int x = N;
V<V<int>> ans;
while(x > 0) {
int nxt = par[x];
ans.push_back({});
while(x > nxt) ans.back().push_back(B[--x].second + 1);
}
cout << sz(ans) << nl;
for(auto& v : ans) {
cout << sz(v) << " ";
for(auto c : v) {
cout << c << " ";
// assert(sz(v) >= A[c - 1]);
}
cout << nl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |