Submission #1107838

# Submission time Handle Problem Language Result Execution time Memory
1107838 2024-11-02T07:19:58 Z coolboy19521 Closing Time (IOI23_closing) C++17
0 / 100
47 ms 8160 KB
#include "closing.h"
#include "bits/stdc++.h"

using ll = long long;
using namespace std;

int max_score(int N, int X, int Y, ll K,
              vector<int> U, vector<int> V, vector<int> W)
{
    ll lo = 0, hi = K;

    vector<ll> x(N), y(N);
    for (int i = X - 1; 0 <= i; i --) {
        x[i] = x[i + 1] + W[i];
    }
    for (int i = X + 1; i < N; i ++) {
        x[i] = x[i - 1] + W[i - 1];
    }
    for (int i = Y + 1; i < N; i ++) {
        y[i] = y[i - 1] + W[i - 1];
    }
    for (int i = Y - 1; 0 <= i; i --) {
        y[i] = y[i + 1] + W[i];
    }

    // cout << "arr:\n";
    // for (int i =  0; i < N; i ++) {
    //     cout << x[i] << ' ';
    // }
    // cout << '\n';

    // for (int i =  0; i < N; i ++) {
    //     cout << y[i] << ' ';
    // }
    // cout << '\n';

    auto check = [&](ll mm){
        ll r = 0;
        ll c = 0;
        for (int i = 0; i < N; i ++) {
            ll mx = max(x[i], y[i]);
            ll mn = min(x[i], y[i]);
            if (mx < mm) {
                r += mx;
                c ++;
            } else if (mn < mm) {
                r += mn;
                c ++;
            }
        }
        return r <= K;
    };

    while (lo < hi) {
        ll mi = (lo + hi + 1) / 2;

        if (check(mi)) {
            lo = mi;
        } else {
            hi = mi - 1;
        }
    }

    int c = 0;
    ll r = 0;
    vector<int> vp;
    for (int i = 0; i < N; i ++) {
        ll mx = max(x[i], y[i]);
        ll mn = min(x[i], y[i]);
        if (mx < lo) {
            r += mx;
            c += 2;
        } else if (mn < lo) {
            r += mn;
            c ++;
        }
        if (mx == lo) {
            if (mn < lo)
                vp.push_back(-1);
            else vp.push_back(-2);
        } else if (mx != mn && mn == lo) {
            vp.push_back(-1);
        }
    }

    // cout << lo << ' ' << c << '\n';

    sort(begin(vp),end(vp));

    for (int i : vp) {
        // cout << "I:" << i << '\n';
        if (r + lo <= K) {
            r += lo;
            c -= i;
        }
    }

    return c;
}

/*

1
3 0 1 1
0 1 1
1 2 1

*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 8160 KB 1st lines differ - on the 1st token, expected: '451', found: '371'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '96', found: '93'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '96', found: '93'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '96', found: '93'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -