# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127106 | eriksuenderhauf | Teams (CEOI11_tea) | C++11 | 568 ms | 74872 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 1; i <= (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e6 + 5;
const double eps = 1e-9;
pii a[MAXN];
int tree[MAXN], pre[MAXN], ans[MAXN];
int dp[MAXN], n, par[MAXN];
int solve(int x)
{
memset(tree, 0, sizeof tree);
tree[0] = 1;
for (int i =1; i <= n; i++)
{
if (i < a[i].fi)
dp[i] = -INF;
else
{
dp[i] = pre[i - a[i].fi] + 1;
if (ans[i - a[i].fi] >= i - x)
tree[i] = 1, par[i] = ans[i - a[i].fi];
}
pre[i] = pre[i - 1];
ans[i] = ans[i - 1];
if (tree[i] && pre[i] <= dp[i])
ans[i] = i, pre[i] = dp[i];
}
return tree[n];
}
void dfs(int u)
{
if (u == 0)
return;
dfs(par[u]);
printf("%d ", u - par[u]);
for (int i = par[u] + 1; i <= u; i++)
printf("%d ", a[i].se);
enl;
}
int main()
{
ni(n);
for (int i = 1; i <= n;i ++)
ni(a[i].fi), a[i].se = i;
sort(a + 1, a + n + 1);
int lo = 1, hi = n;
int sz = n;
while (lo != hi)
{
int mi = (lo + hi) / 2;
if (solve(mi))
hi = mi;
else
lo = mi + 1;
}
solve(lo);
pri(dp[n]);
dfs(n);
return 0;
}
Compilation message (stderr)
# | 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... |