답안 #963054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963054 2024-04-14T12:30:57 Z RaresFelix Chorus (JOI23_chorus) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;  // or double, if TL is tight
using str = string; 
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

const ll INF = 1e18;

struct CHT {
    int p = 0;
    vector<pair<ll, ll> > V;
    void insert(ll a, ll b) { /// ax + b
        //a va scadea mereu
        while(V.size() > 1) {
            auto [a1, b1] = V.end()[-1];
            auto [a2, b2] = V.end()[-2];
            if((b2 - b) * (a1 - a2) <= (b2 - b1) * (a - a2))
                V.pop_back();
            else break;
        }
        V.push_back({a, b});
    }

    ll query(ll x) {
        if(V.empty()) return INF;
        ll re = INF;
        for(auto [a, b] : V)
            re = min(a * x + b);
        return re;
        auto eval = [&](int i) {
            return V[i].first * x + V[i].second;
        };
        while(p + 1 < V.size() && eval(p + 1) <= eval(p)) ++p;
        return eval(p);
    }
};

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;

    string s0, s;
    cin >> s0;
    ll re0 = 0;
    int nrB = 0, sum = 0;
    for(auto it : s0) {
        if(it == 'A') {
            ++sum;
            s += 'A';
            re0 += nrB;
            if(nrB && sum) {
                s += 'B';
                --nrB;
                --sum;
            }
        } else {
            if(sum) {
                s += 'B';
                --sum;
            } else {
                ++nrB;
            }
        }
    }

    vll A, P(n + 1);
    vll SA;
    P[0] = -1;
    for(auto it : s) {
        if(it == 'A'){
            A.push_back(nrB);
            if(SA.empty())
                SA.push_back(A.back());
            else
                SA.push_back(A.back() + SA.back());
        } 
        else {
            ++nrB;
            P[nrB] = (int)A.size() - 1;
        }
    }
    vll SAP(n);
    for(int i = 0; i < n; ++i) {
        SAP[i] = 0;
        if(P[i] != -1) SAP[i] = SA[P[i]];
    }

    auto cost = [&](ll st, ll dr) {
        return st * P[st] - SAP[st] + SA[dr] - st * dr;
    };

    vector<vll> DP(n, vll(k + 1, INF));

    vector<CHT> Sol(k + 1);
    for(int i = 0; i < n; ++i) {
        DP[i][1] = cost(0, i);
        if(i)
            Sol[1].insert(-i, i * P[i] - SAP[i] + DP[i - 1][1]);
        for(int j = 2; j <= k; ++j) {
            if(i)
                Sol[j].insert(-i, DP[i - 1][j] + i * P[i] - SAP[i]);
            DP[i][j] = Sol[j - 1].query(i) + SA[i];
        }
    }

    ll re = INF;
    for(auto it : DP[n - 1]) re = min(re, it);

    cout << re + re0 << "\n";
    return 0;
}

Compilation message

chorus.cpp: In member function 'll CHT::query(ll)':
chorus.cpp:39:31: error: no matching function for call to 'min(std::tuple_element<0, std::pair<long long int, long long int> >::type)'
   39 |             re = min(a * x + b);
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from chorus.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
chorus.cpp:39:31: note:   candidate expects 2 arguments, 1 provided
   39 |             re = min(a * x + b);
      |                               ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from chorus.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
chorus.cpp:39:31: note:   candidate expects 3 arguments, 1 provided
   39 |             re = min(a * x + b);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from chorus.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
chorus.cpp:39:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |             re = min(a * x + b);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from chorus.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
chorus.cpp:39:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |             re = min(a * x + b);
      |                               ^
chorus.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while(p + 1 < V.size() && eval(p + 1) <= eval(p)) ++p;
      |               ~~~~~~^~~~~~~~~~