Submission #127106

# Submission time Handle Problem Language Result Execution time Memory
127106 2019-07-08T22:28:57 Z eriksuenderhauf Teams (CEOI11_tea) C++11
100 / 100
568 ms 74872 KB
//#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

tea.cpp: In function 'int main()':
tea.cpp:70:9: warning: unused variable 'sz' [-Wunused-variable]
     int sz = n;
         ^~
tea.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
tea.cpp:65:5: note: in expansion of macro 'ni'
     ni(n);
     ^~
tea.cpp:67:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         ni(a[i].fi), a[i].se = i;
                    ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 11 ms 8184 KB Output is correct
3 Correct 11 ms 8184 KB Output is correct
4 Correct 10 ms 8184 KB Output is correct
5 Correct 10 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8184 KB Output is correct
2 Correct 11 ms 8184 KB Output is correct
3 Correct 11 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8184 KB Output is correct
2 Correct 12 ms 8184 KB Output is correct
3 Correct 12 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8356 KB Output is correct
2 Correct 15 ms 8312 KB Output is correct
3 Correct 15 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8312 KB Output is correct
2 Correct 15 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 10992 KB Output is correct
2 Correct 46 ms 10744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 11384 KB Output is correct
2 Correct 43 ms 10744 KB Output is correct
3 Correct 50 ms 11256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 34528 KB Output is correct
2 Correct 371 ms 33792 KB Output is correct
3 Correct 340 ms 35192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 486 ms 44152 KB Output is correct
2 Correct 568 ms 74872 KB Output is correct
3 Correct 436 ms 42104 KB Output is correct
4 Correct 428 ms 39740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 42232 KB Output is correct
2 Correct 324 ms 42488 KB Output is correct
3 Correct 479 ms 42616 KB Output is correct
4 Correct 484 ms 44408 KB Output is correct