답안 #832155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832155 2023-08-21T05:07:13 Z skittles1412 전선 연결 (IOI17_wiring) C++17
0 / 100
1000 ms 6508 KB
#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

using ll = long long;

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

ll min_total_length(vector<int> arr_r, vector<int> arr_b) {
    vector<pair<int, bool>> arr;
    for (auto& a : arr_r) {
        arr.emplace_back(a, false);
    }
    for (auto& a : arr_b) {
        arr.emplace_back(a, true);
    }

    sort(begin(arr), end(arr));

    int n = sz(arr);

    long dp[n + 1];
    memset(dp, 0x3f, sizeof(dp));
    dp[n] = 0;

    deque<int> inds[2];

    for (int i = n - 1; i >= 0; i--) {
        if (i + 1 < n) {
            inds[arr[i + 1].second].push_front(i + 1);
        }
        auto [t, ty] = arr[i];

        auto &me = inds[ty], &other = inds[!ty];

        auto get_w = [&](int u, int v) -> long {
            return abs(arr[u].first - arr[v].first);
        };
        auto get = [&](const deque<int>& arr, int ind) -> int {
            if (ind == sz(arr)) {
                return n;
            }
            return arr[ind];
        };

        if (!sz(other)) {
            continue;
        }

        if (get(other, 0) < get(me, 0)) {
            long csum = 0;

            for (int j = 0; j < sz(other) && get(other, j) < get(me, 0); j++) {
                csum += get_w(i, other[j]);
                dp[i] = min(dp[i], csum + min(dp[other[j]], dp[other[j] + 1]));
            }
        } else {
            dp[i] = dp[i + 1] + get_w(i, other[0]);

            long csum = 0;

            me.push_front(i);
            for (int j = 0; j < sz(other) && j < sz(me); j++) {
                csum += get_w(me[j], other[j]);
                dp[i] = min(dp[i],
                            csum + dp[min(get(other, j + 1), get(me, j + 1))]);
            }
            me.pop_front();
        }
    }

    return dp[0];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '25859', found: '26187'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 1082 ms 5544 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '17703', found: '17835'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1071 ms 6508 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '25859', found: '26187'
2 Halted 0 ms 0 KB -