Submission #789575

# Submission time Handle Problem Language Result Execution time Memory
789575 2023-07-21T14:04:06 Z nasam K blocks (IZhO14_blocks) C++17
0 / 100
26 ms 84084 KB
#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;1234567890
#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); }

int MOD = 1e9 + 7;

int add(int &a, int b){ if ((a += b) >= MOD) a -= MOD; return a; }
int sub(int a, int b){ if ((a -= b) < 0) a += MOD; return a; }
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; }

const int MAX = 1e5 + 7;
const ll INF = 1e14;
const int K = 1e2 + 7;

int num, lim;
int val[MAX];
ll dp[MAX][K];
stack<pii> st;

void solve(){
    FOR (j, 2, lim){
        while (st.size())
            st.pop();
        FOR (i, 1, num){
            ll Min = INF;
            while (st.size() && val[st.top().se] <= val[i])
                minimize(Min, st.top().fi),
                st.pop();
            int L = st.empty() ? 0 : st.top().se;
            dp[i][j] = min(dp[L][j], Min + val[i]);
            st.push({min(Min, dp[i][j - 1]), i});
        }
    }
    printf("%lld", dp[num][lim]);
}

void read(){
    memset(dp, 0x3f, sizeof(dp));
    dp[0][1] = 0;
    scanf("%d %d", &num, &lim);
    FOR (i, 1, num)
        scanf("%d", &val[i]),
        dp[i][1] = max(dp[i - 1][1], (ll) val[i]);
}

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

Compilation message

blocks.cpp: In function 'void read()':
blocks.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     scanf("%d %d", &num, &lim);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d", &val[i]),
      |         ~~~~~^~~~~~~~~~~~~~~
blocks.cpp: In function 'int main()':
blocks.cpp:28:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:74:5: note: in expansion of macro 'file'
   74 |     file("main");
      |     ^~~~
blocks.cpp:28:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:74:5: note: in expansion of macro 'file'
   74 |     file("main");
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 84052 KB Output is correct
2 Correct 25 ms 84052 KB Output is correct
3 Correct 25 ms 84044 KB Output is correct
4 Correct 26 ms 84068 KB Output is correct
5 Incorrect 25 ms 83976 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 83984 KB Output is correct
2 Correct 24 ms 84044 KB Output is correct
3 Correct 26 ms 84000 KB Output is correct
4 Correct 26 ms 84076 KB Output is correct
5 Incorrect 26 ms 84084 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 84052 KB Output is correct
2 Correct 25 ms 84052 KB Output is correct
3 Correct 25 ms 84044 KB Output is correct
4 Correct 26 ms 84068 KB Output is correct
5 Incorrect 25 ms 83976 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 84052 KB Output is correct
2 Correct 25 ms 84052 KB Output is correct
3 Correct 25 ms 84044 KB Output is correct
4 Correct 26 ms 84068 KB Output is correct
5 Incorrect 25 ms 83976 KB Output isn't correct
6 Halted 0 ms 0 KB -