답안 #832248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832248 2023-08-21T07:48:33 Z finn__ 전선 연결 (IOI17_wiring) C++17
0 / 100
1 ms 232 KB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
using L = long long;

long long min_total_length(std::vector<int> r, std::vector<int> b)
{
    vector<vector<L>> a;
    auto it = r.begin(), jt = b.begin();

    while (it != r.end() || jt != b.end())
    {
        a.push_back({});
        if (it != r.end() && (jt == b.end() || *it < *jt))
        {
            while (it != r.end() && (jt == b.end() || *it < *jt))
                a.back().push_back(*it), ++it;
        }
        else
        {
            while (jt != b.end() && (it == r.end() || *jt < *it))
                a.back().push_back(*jt), ++jt;
        }
    }

    vector<vector<L>> p = a;
    for (auto &x : p)
        for (size_t i = 1; i < x.size(); ++i)
            x[i] += x[i - 1];

    // dp state, suffix min, prefix min - k * d
    vector<vector<L>> f(a.size()), g(a.size()), h(a.size());
    for (size_t i = 0; i < a.size(); ++i)
    {
        f[i].resize(a[i].size() + 1);
        g[i].resize(a[i].size() + 1);
        h[i].resize(a[i].size() + 1);
        fill(f[i].begin(), f[i].end(), LLONG_MAX / 4);
        fill(g[i].begin(), g[i].end(), LLONG_MAX / 4);
        fill(h[i].begin(), h[i].end(), LLONG_MAX / 4);

        for (L j = 0; j <= a[i].size(); ++j)
        {
            if ((!i && j) || (i == a.size() - 1 && j != a[i].size()))
                continue;
            L d = !i ? 0 : a[i][0] - a[i - 1].back();
            f[i][j] = (j ? p[i][j - 1] : 0) - j * a[i][0];
            if (i)
            {
                f[i][j] += min(j <= a[i - 1].size() ? g[i - 1][j] : LLONG_MAX / 4,
                               j ? (h[i - 1][min<size_t>(j - 1, a[i - 1].size())] + j * d) : LLONG_MAX / 4);
            }

            if (i + 1 < a.size())
            {
                L right_cost = -(p[i].back() - (j ? p[i][j - 1] : 0)) + (L)(a[i].size() - j) * a[i + 1][0];
                g[i][j] = f[i][j] + right_cost;
                h[i][j] = f[i][j] + right_cost - j * (a[i + 1][0] - a[i].back());

                if (j)
                    h[i][j] = min(h[i][j], h[i][j - 1]);
            }
        }

        for (size_t j = a[i].size() - 1; j < a[i].size(); --j)
            g[i][j] = min(g[i][j], g[i][j + 1]);
    }

    return f.back().back();
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:42:25: warning: comparison of integer expressions of different signedness: 'L' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (L j = 0; j <= a[i].size(); ++j)
      |                       ~~^~~~~~~~~~~~~~
wiring.cpp:44:54: warning: comparison of integer expressions of different signedness: 'L' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             if ((!i && j) || (i == a.size() - 1 && j != a[i].size()))
      |                                                    ~~^~~~~~~~~~~~~~
wiring.cpp:50:34: warning: comparison of integer expressions of different signedness: 'L' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                 f[i][j] += min(j <= a[i - 1].size() ? g[i - 1][j] : LLONG_MAX / 4,
      |                                ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '25859', found: '43706'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '904', found: '2305843009213694232'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 232 KB 3rd lines differ - on the 1st token, expected: '316', found: '2305843009213694091'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '27', found: '30'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '25859', found: '43706'
2 Halted 0 ms 0 KB -