Submission #682114

# Submission time Handle Problem Language Result Execution time Memory
682114 2023-01-15T19:58:22 Z opPO Money (IZhO17_money) C++17
45 / 100
1500 ms 41572 KB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;
int n;

vec<int> merge(vec<int> a, vec<int> b)
{
    reverse(all(b));
    for (int i = 0; i < sz(b) - 1; i++) if (b[i] > b[i + 1]) return {};
    if (a.empty()) return b;
    for (int i = 0; i <= sz(a); i++)
    {
        int prv = (!i ? -1 : a[i - 1]);
        int nxt = (i == sz(a) ? OO : a[i]);
        if (b[0] >= prv && b.back() <= nxt)
        {
            vec<int> ret;
            for (int j = 0; j < i; j++) ret.pb(a[j]);
            for (int j = 0; j < sz(b); j++) ret.pb(b[j]);
            for (int j = i; j < sz(a); j++) ret.pb(a[j]);
            return ret;
        }
    }
    return a;
}

void solve()
{
    cin >> n;
    vec<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    vec<int> dp(n + 1, OO);
    vec<vec<int>> best(n + 1);
    dp[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        vec<int> b;
        for (int j = i; j >= 1; j--)
        {
            b.pb(a[j]);
            if (sz(merge(best[j - 1], b)) == i)
            {
                if (dp[j - 1] + 1 < dp[i])
                {
                    dp[i] = dp[j - 1] + 1;
                    best[i] = merge(best[j - 1], b);
                }
            }
        }
    }
    cout << dp[n];
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 0 ms 224 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 0 ms 224 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 10 ms 852 KB Output is correct
33 Correct 10 ms 980 KB Output is correct
34 Correct 10 ms 852 KB Output is correct
35 Correct 10 ms 964 KB Output is correct
36 Correct 10 ms 852 KB Output is correct
37 Correct 13 ms 896 KB Output is correct
38 Correct 10 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 324 KB Output is correct
18 Correct 0 ms 224 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 4 ms 596 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 10 ms 852 KB Output is correct
33 Correct 10 ms 980 KB Output is correct
34 Correct 10 ms 852 KB Output is correct
35 Correct 10 ms 964 KB Output is correct
36 Correct 10 ms 852 KB Output is correct
37 Correct 13 ms 896 KB Output is correct
38 Correct 10 ms 968 KB Output is correct
39 Execution timed out 1565 ms 41572 KB Time limit exceeded
40 Halted 0 ms 0 KB -