Submission #859434

# Submission time Handle Problem Language Result Execution time Memory
859434 2023-10-10T07:18:35 Z Alexandruabcde Measures (CEOI22_measures) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 2e5 + 5;
typedef long long LL;
typedef long double LD;
constexpr LL INF = 1LL * 1e18;

int N, M, D;
int A[NMAX];
int B[NMAX];

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M >> D;
    for (int i = 1; i <= N; ++ i )
        cin >> A[i];
    for (int i = 1; i <= M; ++ i )
        cin >> B[i];
}

bool Check (LD t, int m) {
    LD first_dist = -INF;
    int i = 1, j = 1;

    while (i <= N || j <= m) {
        LD next_dist = 0;

        if (i <= N && (A[i] <= B[j] || j > m)) {
            next_dist = max(first_dist + D, A[i] - t);

            if (next_dist < A[i] - t || next_dist > A[i] + t) return false;
            ++ i;
        }
        else {
            next_dist = max(first_dist + D, B[j] - t);

            if (next_dist < B[j] - t || next_dist > B[j] + t) return false;
            ++ j;
        }

        first_dist = next_dist;
    }

    return true;
}

void Solve_FirstCase () {
    sort(A+1, A+N+1);

    for (int i = 1; i <= M; ++ i ) {
        sort(B+1, B+i+1);

        LL st = 0, dr = INF;
        LD ans = 0;

        while (st <= dr) {
            LL mij = (st + dr) / 2;

            if (Check(mij*.5, i)) {
                dr = mij - 1;
                ans = mij * .5;
            }
            else st = mij + 1;
        }

        cout << ans << " ";
    }
}

void Solve_SecondCase () {
    LL worst_case = -INF;
    LD answer = 0;

    for (int j = 1; j <= M; ++ j ) {
        LL new_pos_ans = 1LL * j * D - B[j] + worst_case;

        answer = max(answer, new_pos_ans * .5);

        cout << answer << '\n';

        worst_case = max(worst_case, B[j] - 1LL * j * D);
    }
}

int main()
{
    Read();
    if (M <= 10)
        Solve_FirstCase();
    else Solve_SecondCase();

    return 0;
}

Compilation message

Main.cpp: In function 'void Solve_SecondCase()':
Main.cpp:81:46: error: no matching function for call to 'max(LD&, double)'
   81 |         answer = max(answer, new_pos_ans * .5);
      |                                              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:81:46: note:   deduced conflicting types for parameter 'const _Tp' ('long double' and 'double')
   81 |         answer = max(answer, new_pos_ans * .5);
      |                                              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:81:46: note:   deduced conflicting types for parameter 'const _Tp' ('long double' and 'double')
   81 |         answer = max(answer, new_pos_ans * .5);
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:81:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'long double'
   81 |         answer = max(answer, new_pos_ans * .5);
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:81:46: note:   mismatched types 'std::initializer_list<_Tp>' and 'long double'
   81 |         answer = max(answer, new_pos_ans * .5);
      |                                              ^