답안 #1038204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038204 2024-07-29T14:18:41 Z Beerus13 K개의 묶음 (IZhO14_blocks) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b)  for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; --i)
#define REP(i, a, b)  for(int i = (a), _b = (b); i < _b;  ++i)
#define REPD(i, b, a) for(int i = (b), _a = (a); i > _a;  --i)
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define __builtin_popcount __builtin_popcountll
#define all(val) val.begin(), val.end()
#define ll long long
#define ull unsigned long long
#define lb long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define cd complex<double>
const double PI = acos(-1);
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll Rand(ll l, ll r) {return l + rng() % (r - l + 1);}

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pii, null_type,less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// - insert(x),erase(x)
// - find_by_order(k): return iterator to the k-th smallest element
// - order_of_key(x): the number of elements that are strictly smaller

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } else return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } else return false;
    }
template<class T>
    T Abs(const T &x) {
        return (x < 0 ? -x : x);
    }

const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 1e5 + 5;
const int K = 105;

int n, k, a[N];
ll dp[N], dp_before[N];

void process() {
    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    dp[0] = 0;
    FOR(i, 1, n) dp[i] = max(dp[i - 1], a[i]);
    FOR(j, 2, k) {
        swap(dp_before, dp);
        memset(dp, 0x3f, sizeof(dp));
        stack<pii> st;
        st.emplace(0, 0);
        a[0] = inf;
        FOR(i, j, n) {
            ll res = dp_before[i - 1];
            while(a[st.top().fi] <= a[i]) {
                minimize(res, st.top().se);
                st.pop();
            }
            dp[i] = min(dp[st.top().se], res + a[i]);
            st.emplace(i, res);
        }
    }
    cout << dp[n] << '\n';
}

signed main() { 
    if(fopen("test.inp","r")) {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    // clock_t start = clock()

    int ntests = 1;
    // cin >> ntests;
    while(ntests--) process();

    // cerr << "Time elapsed: " << clock() - start << " ms!\n";
    return 0;
}
// https://oj.uz/problem/view/IZhO14_blocks

Compilation message

blocks.cpp: In function 'void process()':
blocks.cpp:62:45: error: no matching function for call to 'max(long long int&, int&)'
   62 |     FOR(i, 1, n) dp[i] = max(dp[i - 1], a[i]);
      |                                             ^
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 blocks.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:
blocks.cpp:62:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   62 |     FOR(i, 1, n) dp[i] = max(dp[i - 1], a[i]);
      |                                             ^
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 blocks.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:
blocks.cpp:62:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   62 |     FOR(i, 1, n) dp[i] = max(dp[i - 1], a[i]);
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from blocks.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:
blocks.cpp:62:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   62 |     FOR(i, 1, n) dp[i] = max(dp[i - 1], a[i]);
      |                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from blocks.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:
blocks.cpp:62:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   62 |     FOR(i, 1, n) dp[i] = max(dp[i - 1], a[i]);
      |                                             ^
blocks.cpp: In function 'int main()':
blocks.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~