답안 #677431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677431 2023-01-03T10:03:50 Z stanislavpolyn Measures (CEOI22_measures) C++17
0 / 100
1500 ms 844 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? (a = b, 1) : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? (a = b, 1) : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 3e5 + 5;

int n, m;
ll D;
ll a[N];
ll b[N];
ll d[N];
ll suff[N];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> m >> D;

    D *= 2;

    fr (i, 1, n) {
        cin >> a[i];
        a[i] *= 2;
    }

    fr (i, 1, m) {
        ll x;
        cin >> x;
        x *= 2;
        a[++n] = x;
        sort(a + 1, a + 1 + n);

        auto possible = [&](ll t) {
            fr (i, 1, n) b[i] = a[i];

            fr (i, 1, n) {
                ll have = t;
                if (i > 1) {
                    ll x = b[i] - b[i - 1];
                    if (x < D) {
                        if (D - x > t) {
                            return 0;
                        }
                        have -= max(0LL, D - x);
                        b[i] = b[i - 1] + D;
                    }
                }
                if (i == 1 || b[i] - b[i - 1] > D) {
                    if (i == 1) b[i] -= t;
                    else b[i] -= min(b[i] - b[i - 1] - D, have);
                }
            }
            return 1;
        };

       auto possible2 = [&](ll t) {
            fr (i, 1, n - 1) d[i] = a[i + 1] - a[i];
            fr (i, 1, n) suff[i] = 0;

            ll sum = 0;
            fr (i, 1, n - 1) {
                sum += max(0LL, D - d[i]);
            }
            return  sum <= t;
        };


        ll l = 0;
        ll r = 2e18;
        while (l < r) {
            ll mid = l + ((r - l) >> 1);
            if (possible2(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        assert(possible2(l));

        l /= 2;

        cout << l / 2;
        if (l % 2) cout << ".5";
        cout << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:78:14: warning: variable 'possible' set but not used [-Wunused-but-set-variable]
   78 |         auto possible = [&](ll t) {
      |              ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1580 ms 844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1580 ms 844 KB Time limit exceeded
2 Halted 0 ms 0 KB -