Submission #520619

# Submission time Handle Problem Language Result Execution time Memory
520619 2022-01-30T10:53:24 Z Vimmer Cigle (COI21_cigle) C++14
48 / 100
1000 ms 218324 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")

#define F first
#define S second
#define PB push_back
#define M ll(1e9 + 7)
#define sz(x) (ll)x.size()
#define N 1000500
#define pri(x) cout << x << endl
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

using namespace std;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

si f[5001][5001][2];

vector <int> was[5001];

int pr[5001];

si now[5001][5001][2];

int main()
{
    istream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    memset(f, -1, sizeof f);

    int n;

    cin >> n;

    int a[n];

    si ans = 0;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < n; i++)
    {
        pr[i] = a[i];

        if (i)
            pr[i] += pr[i - 1];
    }

    for (int l = 0; l < n; l++)
        {
            int sum = 0;

            for (int r = l; r < n; r++)
            {
                sum += a[r];

                int L = r + 1, R = n - 1;

                while (L < R)
                {
                    int md = (L + R) >> 1;

                    if (pr[md] - pr[r] >= sum)
                        R = md;
                            else L = md + 1;
                }

                if (pr[L] - pr[r] == sum)
                    {
                        was[r].PB(L);
                    }
            }
        }

    for (int i = 0; i < n; i++)
        sort(all(was[i]));

    memset(now, -1, sizeof now);

    for (int i = 0; i < n; i++)
        f[0][i][0] = 0;

    for (int r = 0; r < n; r++)
        for (int l = 0; l <= r; l++)
                for (int t = 0; t < 2; t++)
                {
                    if (r)
                        now[l][r][t] = max(now[l][r][t], now[l][r - 1][t]);

                    f[l][r][t] = max(f[l][r][t], now[l][r][t]);

                    ans = max(ans, f[l][r][t]);

                    if (f[l][r][t] != -1)
                        {
                            si kl = f[l][r][t];

                            int sm = pr[r], cur = 0;

                            if (l)
                                sm -= pr[l - 1];

                            for (auto nw : was[r])
                            {
                                cur = pr[nw] - pr[r];

                                if (cur >= sm)
                                {
                                    now[r + 1][nw][t ^ 1] = max(now[r + 1][nw][t ^ 1], si(kl));

                                    break;
                                }
                                else
                                {
                                    if (nw != n - 1)
                                        {
                                            kl++;

                                            now[r + 1][nw + 1][t ^ 1] = max(now[r + 1][nw + 1][t ^ 1], si(kl));
                                        }

                                    ans = max(ans, kl);
                                }
                            }
                        }
                }

    pri(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 70 ms 196120 KB Output is correct
2 Correct 76 ms 196140 KB Output is correct
3 Correct 70 ms 196060 KB Output is correct
4 Correct 68 ms 196160 KB Output is correct
5 Correct 69 ms 196136 KB Output is correct
6 Correct 69 ms 196080 KB Output is correct
7 Correct 69 ms 196072 KB Output is correct
8 Correct 69 ms 196160 KB Output is correct
9 Correct 69 ms 196168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 196120 KB Output is correct
2 Correct 76 ms 196140 KB Output is correct
3 Correct 70 ms 196060 KB Output is correct
4 Correct 68 ms 196160 KB Output is correct
5 Correct 69 ms 196136 KB Output is correct
6 Correct 69 ms 196080 KB Output is correct
7 Correct 69 ms 196072 KB Output is correct
8 Correct 69 ms 196160 KB Output is correct
9 Correct 69 ms 196168 KB Output is correct
10 Correct 72 ms 196140 KB Output is correct
11 Correct 70 ms 196160 KB Output is correct
12 Correct 69 ms 196132 KB Output is correct
13 Correct 70 ms 196128 KB Output is correct
14 Correct 70 ms 196164 KB Output is correct
15 Correct 74 ms 196280 KB Output is correct
16 Correct 70 ms 196164 KB Output is correct
17 Correct 69 ms 196068 KB Output is correct
18 Correct 69 ms 196164 KB Output is correct
19 Correct 72 ms 196064 KB Output is correct
20 Correct 69 ms 196164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 196364 KB Output is correct
2 Correct 156 ms 196480 KB Output is correct
3 Correct 136 ms 196400 KB Output is correct
4 Correct 139 ms 196332 KB Output is correct
5 Correct 148 ms 196460 KB Output is correct
6 Correct 150 ms 196420 KB Output is correct
7 Correct 140 ms 196440 KB Output is correct
8 Correct 140 ms 196420 KB Output is correct
9 Correct 142 ms 196352 KB Output is correct
10 Correct 141 ms 196320 KB Output is correct
11 Correct 135 ms 196404 KB Output is correct
12 Correct 141 ms 196404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 196120 KB Output is correct
2 Correct 76 ms 196140 KB Output is correct
3 Correct 70 ms 196060 KB Output is correct
4 Correct 68 ms 196160 KB Output is correct
5 Correct 69 ms 196136 KB Output is correct
6 Correct 69 ms 196080 KB Output is correct
7 Correct 69 ms 196072 KB Output is correct
8 Correct 69 ms 196160 KB Output is correct
9 Correct 69 ms 196168 KB Output is correct
10 Correct 72 ms 196140 KB Output is correct
11 Correct 70 ms 196160 KB Output is correct
12 Correct 69 ms 196132 KB Output is correct
13 Correct 70 ms 196128 KB Output is correct
14 Correct 70 ms 196164 KB Output is correct
15 Correct 74 ms 196280 KB Output is correct
16 Correct 70 ms 196164 KB Output is correct
17 Correct 69 ms 196068 KB Output is correct
18 Correct 69 ms 196164 KB Output is correct
19 Correct 72 ms 196064 KB Output is correct
20 Correct 69 ms 196164 KB Output is correct
21 Correct 126 ms 196364 KB Output is correct
22 Correct 156 ms 196480 KB Output is correct
23 Correct 136 ms 196400 KB Output is correct
24 Correct 139 ms 196332 KB Output is correct
25 Correct 148 ms 196460 KB Output is correct
26 Correct 150 ms 196420 KB Output is correct
27 Correct 140 ms 196440 KB Output is correct
28 Correct 140 ms 196420 KB Output is correct
29 Correct 142 ms 196352 KB Output is correct
30 Correct 141 ms 196320 KB Output is correct
31 Correct 135 ms 196404 KB Output is correct
32 Correct 141 ms 196404 KB Output is correct
33 Correct 128 ms 196424 KB Output is correct
34 Correct 139 ms 196404 KB Output is correct
35 Correct 139 ms 196296 KB Output is correct
36 Correct 145 ms 196444 KB Output is correct
37 Correct 151 ms 196556 KB Output is correct
38 Correct 144 ms 196384 KB Output is correct
39 Correct 95 ms 196164 KB Output is correct
40 Correct 74 ms 196160 KB Output is correct
41 Correct 77 ms 196200 KB Output is correct
42 Correct 79 ms 196104 KB Output is correct
43 Correct 75 ms 196168 KB Output is correct
44 Correct 78 ms 196176 KB Output is correct
45 Correct 77 ms 196164 KB Output is correct
46 Correct 76 ms 196164 KB Output is correct
47 Correct 75 ms 196140 KB Output is correct
48 Correct 81 ms 196204 KB Output is correct
49 Correct 79 ms 196164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 196120 KB Output is correct
2 Correct 76 ms 196140 KB Output is correct
3 Correct 70 ms 196060 KB Output is correct
4 Correct 68 ms 196160 KB Output is correct
5 Correct 69 ms 196136 KB Output is correct
6 Correct 69 ms 196080 KB Output is correct
7 Correct 69 ms 196072 KB Output is correct
8 Correct 69 ms 196160 KB Output is correct
9 Correct 69 ms 196168 KB Output is correct
10 Correct 72 ms 196140 KB Output is correct
11 Correct 70 ms 196160 KB Output is correct
12 Correct 69 ms 196132 KB Output is correct
13 Correct 70 ms 196128 KB Output is correct
14 Correct 70 ms 196164 KB Output is correct
15 Correct 74 ms 196280 KB Output is correct
16 Correct 70 ms 196164 KB Output is correct
17 Correct 69 ms 196068 KB Output is correct
18 Correct 69 ms 196164 KB Output is correct
19 Correct 72 ms 196064 KB Output is correct
20 Correct 69 ms 196164 KB Output is correct
21 Correct 126 ms 196364 KB Output is correct
22 Correct 156 ms 196480 KB Output is correct
23 Correct 136 ms 196400 KB Output is correct
24 Correct 139 ms 196332 KB Output is correct
25 Correct 148 ms 196460 KB Output is correct
26 Correct 150 ms 196420 KB Output is correct
27 Correct 140 ms 196440 KB Output is correct
28 Correct 140 ms 196420 KB Output is correct
29 Correct 142 ms 196352 KB Output is correct
30 Correct 141 ms 196320 KB Output is correct
31 Correct 135 ms 196404 KB Output is correct
32 Correct 141 ms 196404 KB Output is correct
33 Correct 128 ms 196424 KB Output is correct
34 Correct 139 ms 196404 KB Output is correct
35 Correct 139 ms 196296 KB Output is correct
36 Correct 145 ms 196444 KB Output is correct
37 Correct 151 ms 196556 KB Output is correct
38 Correct 144 ms 196384 KB Output is correct
39 Correct 95 ms 196164 KB Output is correct
40 Correct 74 ms 196160 KB Output is correct
41 Correct 77 ms 196200 KB Output is correct
42 Correct 79 ms 196104 KB Output is correct
43 Correct 75 ms 196168 KB Output is correct
44 Correct 78 ms 196176 KB Output is correct
45 Correct 77 ms 196164 KB Output is correct
46 Correct 76 ms 196164 KB Output is correct
47 Correct 75 ms 196140 KB Output is correct
48 Correct 81 ms 196204 KB Output is correct
49 Correct 79 ms 196164 KB Output is correct
50 Execution timed out 1100 ms 218324 KB Time limit exceeded
51 Halted 0 ms 0 KB -