Submission #701328

# Submission time Handle Problem Language Result Execution time Memory
701328 2023-02-20T23:09:26 Z PurpleCrayon Measures (CEOI22_measures) C++17
10 / 100
1500 ms 6968 KB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 2e5+10, MOD = 998244353;
const ll INF = 1e18+10;

void solve() {
    int n, m, d; cin >> n >> m >> d;
    vector<int> a(n); for (auto& x : a) cin >> x;
    vector<int> b(m); for (auto& x : b) cin >> x;

    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        v.emplace_back(a[i], i);
    }
    for (int i = 0; i < m; i++) {
        v.emplace_back(b[i], n + i);
    }

    sort(v.begin(), v.end());

    vector<int> loc_a(n), loc_b(m);
    for (int i = 0; i < n + m; i++) {
        if (v[i].second < n) {
            loc_a[v[i].second] = i;
        } else {
            loc_b[v[i].second - n] = i;
        }
    }

    // end[i] = max(a[i] - t, end[i-1] + d)
    // final condition: end[i] <= a[i] + t
    //
    // end[i] = max(a[i], end[i-1] + d)
    // final condition: end[i] <= a[i] + 2 * t
    //
    // end[i] = max((i - j) * d + a[j])
    // final conditoin: end[i] <= a[i] + 2 * t
    // t = max((i - j) * d + a[j] - a[i]) / 2
    // t = max((i * d - a[i] - (j * d - a[j])) / 2

    // D * i - x

    vector<ll> val(n + m);
    vector<bool> on(n + m);
    for (int i = 0; i < n; i++) {
        val[loc_a[i]] = -a[i];
    }
    for (int i = 0; i < m; i++) {
        val[loc_b[i]] = -b[i];
     }

    auto activate = [&](int i) {
        for (int j = i + 1; j < n + m; j++) {
            val[j] += d;
        }
        on[i] = 1;
    };


    for (int i = 0; i < n; i++) {
        activate(loc_a[i]);
    }

    for (int i = 0; i < m; i++) {
        activate(loc_b[i]);

        ll ans = 0;
        for (int x = 0; x < n + m; x++) if (on[x]) {
            for (int y = x + 1; y < n + m; y++) if (on[y]) {
                ans = max(ans, val[y] - val[x]);
            }
        }
        cout << ans / 2;
        if (ans % 2) cout << ".5";
        cout << ' ';
    }
    cout << '\n';
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 368 KB Output is correct
2 Correct 25 ms 372 KB Output is correct
3 Correct 33 ms 340 KB Output is correct
4 Correct 24 ms 340 KB Output is correct
5 Correct 26 ms 396 KB Output is correct
6 Correct 24 ms 340 KB Output is correct
7 Correct 36 ms 340 KB Output is correct
8 Correct 33 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 368 KB Output is correct
2 Correct 25 ms 372 KB Output is correct
3 Correct 33 ms 340 KB Output is correct
4 Correct 24 ms 340 KB Output is correct
5 Correct 26 ms 396 KB Output is correct
6 Correct 24 ms 340 KB Output is correct
7 Correct 36 ms 340 KB Output is correct
8 Correct 33 ms 340 KB Output is correct
9 Execution timed out 1573 ms 6968 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1574 ms 4948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1574 ms 4948 KB Time limit exceeded
2 Halted 0 ms 0 KB -