답안 #872944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872944 2023-11-14T07:00:58 Z nasam K개의 묶음 (IZhO14_blocks) C++17
0 / 100
19 ms 80476 KB
/*************************************
*       author: Pham Huy Khanh       *
*************************************/
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define CNTBIT(x) __builtin_popcount(x)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define left ___left
#define right ___right
#define pii pair<int, int>
#define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl;
#define lob lower_bound // >=
#define upb upper_bound // >
#define endl "\n"

using namespace std;

template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; }
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; }

#define  gogobruhbruh  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }

const int MOD = 1e9 + 7;

void add(int &a, int b){ if ((a += b) >= MOD) a -= MOD; }
void sub(int &a, int b){ if ((a -= b) < 0) a += MOD - 1; }
int muti(int a, int b){ return (1LL * a * b) % MOD; }
int Pow(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = muti(res, x); x = muti(x, x); } return res; }
int Pow2(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = 1LL * res * x % (MOD - 1); x = 1LL * x * x % (MOD - 1); } return res; }

const int MAX = 1e5 + 2;
const int K = 1e2 + 2;
const int INF = 2e9 + 7;

int num, lim;
int a[MAX];
ll dp[MAX][K];
stack<pii> st;
 
void solve(){
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    FOR (j, 1, lim){
        while (st.size())
            st.pop();
        FOR (i, 1, num){
            ll Min = dp[i - 1][j - 1];
            while (st.size() && a[st.top().se] <= a[i])
                minimize(Min, st.top().fi),
                st.pop();
            int L = st.empty() ? 0 : st.top().se;
            dp[i][j] = dp[L][j];
            FOR (k, L + 1, i - 1)
                minimize(dp[i][j], dp[k - 1][j - 1] + a[i]);
            st.push({Min, i});
        }
    }
    cout << dp[num][lim];
}
 
void read(){
    cin >> num >> lim;
    FOR (i, 1, num)
        cin >> a[i];
}

int main(){
    gogobruhbruh;
    file("main");
    int test = 1;
//    cin >> test;
    while (test--)
        read(),
        solve();
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:31:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:79:5: note: in expansion of macro 'file'
   79 |     file("main");
      |     ^~~~
blocks.cpp:31:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:79:5: note: in expansion of macro 'file'
   79 |     file("main");
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 80476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 80472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 80476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 80476 KB Output isn't correct
2 Halted 0 ms 0 KB -