답안 #446832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446832 2021-07-23T12:14:08 Z Nima_Naderi Teams (CEOI11_tea) C++14
100 / 100
557 ms 90656 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]
   70 |     int sz = n;
      |         ^~
tea.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define ni(n) scanf("%d", &(n))
      |               ~~~~~^~~~~~~~~~~~
tea.cpp:65:5: note: in expansion of macro 'ni'
   65 |     ni(n);
      |     ^~
tea.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define ni(n) scanf("%d", &(n))
      |               ~~~~~^~~~~~~~~~~~
tea.cpp:67:9: note: in expansion of macro 'ni'
   67 |         ni(a[i].fi), a[i].se = i;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 8 ms 8140 KB Output is correct
3 Correct 8 ms 8140 KB Output is correct
4 Correct 7 ms 8164 KB Output is correct
5 Correct 6 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8140 KB Output is correct
2 Correct 10 ms 8140 KB Output is correct
3 Correct 9 ms 8152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8140 KB Output is correct
2 Correct 12 ms 8156 KB Output is correct
3 Correct 10 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 8268 KB Output is correct
2 Correct 19 ms 8296 KB Output is correct
3 Correct 15 ms 8292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8268 KB Output is correct
2 Correct 13 ms 8252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 10320 KB Output is correct
2 Correct 49 ms 10764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 10732 KB Output is correct
2 Correct 46 ms 10692 KB Output is correct
3 Correct 53 ms 11128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 30812 KB Output is correct
2 Correct 348 ms 33964 KB Output is correct
3 Correct 363 ms 35012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 442 ms 38256 KB Output is correct
2 Correct 557 ms 90656 KB Output is correct
3 Correct 439 ms 42068 KB Output is correct
4 Correct 412 ms 39620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 433 ms 35360 KB Output is correct
2 Correct 341 ms 42480 KB Output is correct
3 Correct 437 ms 42564 KB Output is correct
4 Correct 458 ms 44360 KB Output is correct