Submission #1053890

# Submission time Handle Problem Language Result Execution time Memory
1053890 2024-08-11T20:07:38 Z SamAnd Bikeparking (EGOI24_bikeparking) C++17
16 / 100
1000 ms 5140 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 300005;
const int INF = 1000000009;

int n;
int x[N], y[N];
int cx[N], cy[N];

int stg(int p)
{
    for (int i = 1; i <= n; ++i)
    {
        cx[i] = x[i];
        cy[i] = y[i];
    }

    int ans = -p;

    int s = p;
    for (int i = n; i >= 1; --i)
    {
        if (x[i] >= s)
        {
            x[i] -= s;
            s = 0;
        }
        else
        {
            s -= x[i];
            x[i] = 0;
        }
    }
    assert(s == 0);

    s = p;
    for (int i = 1; i <= n; ++i)
    {
        if (y[i] >= s)
        {
            y[i] -= s;
            s = 0;
        }
        else
        {
            s -= y[i];
            y[i] = 0;
        }
    }
    assert(s == 0);

    int i = 1;
    int j = 1;
    while (i <= n && j <= n)
    {
        if (x[i] == 0)
        {
            ++i;
            continue;
        }
        if (y[j] == 0)
        {
            ++j;
            continue;
        }
        if (i > j)
        {
            for (int i = 1; i <= n; ++i)
            {
                x[i] = cx[i];
                y[i] = cy[i];
            }
            return -INF;
        }
        int minu = min(x[i], y[j]);
        if (x[i] >= y[j])
        {
            x[i] -= y[j];
            y[j] = 0;
        }
        else
        {
            y[j] -= x[i];
            x[i] = 0;
        }
        if (i < j)
            ans += minu;
    }

    for (int i = 1; i <= n; ++i)
    {
        x[i] = cx[i];
        y[i] = cy[i];
    }

    return ans;
}

void solv()
{
    n = rnd() % 10 + 1;
    for (int i = 1; i <= n; ++i)
        x[i] = rnd() % 20;
    for (int i = 1; i <= n; ++i)
        y[i] = rnd() % 20;

    int ss = 0;
    for (int i = 1; i <= n; ++i)
        ss += x[i];
    for (int i = 1; i <= n; ++i)
        ss -= y[i];
    if (ss < 0)
    {
        for (int i = 1; i <= n; ++i)
            swap(x[i], y[i]);
    }

    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
    for (int i = 1; i <= n; ++i)
        cin >> y[i];

    int s = 0;
    for (int i = 1; i <= n; ++i)
        s += x[i];
    for (int i = 1; i <= n; ++i)
        s -= y[i];
    assert(s >= 0);

    for (int i = n; i >= 1; --i)
    {
        if (x[i] >= s)
        {
            x[i] -= s;
            s = 0;
        }
        else
        {
            s -= x[i];
            x[i] = 0;
        }
    }
    assert(s == 0);

    for (int i = 1; i <= n; ++i)
        s += x[i];

    int ans = -s;
    /*for (int p = 0; p <= s; ++p)
    {
        ans = max(ans, stg(p));
        cout << stg(p) << ' ';
    }
    cout << "\n";*/

    int l = 0, r = s - 1;
    while (l <= r)
    {
        int m = (l + r) / 2;
        int yans = stg(m);
        ans = max(ans, yans);
        int l2 = m + 1, r2 = s;
        int u = m;
        while (l2 <= r2)
        {
            int m2 = (l2 + r2) / 2;
            if (yans == stg(m2))
            {
                u = m2;
                l2 = m2 + 1;
            }
            else
                r2 = m2 - 1;
        }

        if (yans < stg(u + 1))
            l = m + 1;
        else
            r = m - 1;
    }

    cout << ans << "\n";
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);

    int tt = 1;
    //cin >> tt;
    while (tt--)
    {
        solv();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4468 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4568 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 15 ms 2908 KB Output is correct
6 Correct 402 ms 5140 KB Output is correct
7 Execution timed out 1012 ms 4952 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 17 ms 2908 KB Output is correct
3 Correct 408 ms 4988 KB Output is correct
4 Incorrect 1 ms 4440 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4468 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4568 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4464 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 0 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 0 ms 4444 KB Output is correct
32 Correct 0 ms 4444 KB Output is correct
33 Correct 0 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 0 ms 4444 KB Output is correct
36 Correct 0 ms 4444 KB Output is correct
37 Correct 0 ms 4444 KB Output is correct
38 Correct 0 ms 4444 KB Output is correct
39 Correct 0 ms 4444 KB Output is correct
40 Correct 0 ms 4444 KB Output is correct
41 Correct 0 ms 4444 KB Output is correct
42 Correct 0 ms 4444 KB Output is correct
43 Correct 0 ms 4444 KB Output is correct
44 Incorrect 0 ms 4444 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4468 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4568 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 15 ms 2908 KB Output is correct
27 Correct 402 ms 5140 KB Output is correct
28 Execution timed out 1012 ms 4952 KB Time limit exceeded
29 Halted 0 ms 0 KB -