Submission #1104993

# Submission time Handle Problem Language Result Execution time Memory
1104993 2024-10-25T05:13:13 Z dophu K blocks (IZhO14_blocks) C++17
0 / 100
13 ms 84304 KB
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll mod=1e9+7;
const ll inf=1e17;
const ll N=1e5+2;
const ll blocks=1e2+2;
ll dp[N][blocks];
ll rm[N][32];
ll a[N];
ll n,k;
void build(ll lgg) {
    for (ll i=1;i<=lgg;i++) {
        for (ll j=1;j+(1<<i)-1<=n;j++) {
            rm[j][i]=max(rm[j][i-1],rm[j+(1<<(i-1))][i-1]);
        }
    }
}
ll get(ll l,ll r) {
    ll k=__lg(r-l+1);
    return max(rm[l][k],rm[r-(1<<k)+1][k]);
}
ll minn[N];
stack <pll> st[blocks];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("p1.inp","r")) {
      freopen("p1.inp","r",stdin);
      freopen("p1.out","w",stdout);
    }
    if (fopen("blocks.in","r")) {
        freopen("blocks.in","r",stdin);
        freopen("blocks.out","w",stdout);
    }
    memset(dp,0x3f3f,sizeof(dp));
    cin>>n>>k;
    for (ll i=1;i<=n;i++) {
        cin>>a[i];
        rm[i][0]=a[i];
    }
    build(__lg(n));
    for (ll i=1;i<=n;i++) dp[i][1]=get(1,i);
    st[1].push({a[1],1});
    for (ll i=2;i<=k;i++) {
      st[i].push({a[1],1});
      for (ll j=i;j<=n;j++) {
        dp[j][i]=dp[j-1][i-1]+a[i]; /// 1 elm
        ll init=dp[j-1][i-1];
        /// xet cac ptu tang dan
        while (st[i].size() && a[st[i].top().second] <= a[j]) {
            init=min(init,st[i].top().first);
            st[i].pop();
        }
        if (!st[i].size()) {
          continue;
        }
        else {
          dp[j][i]=dp[st[i].top().second][i];
        }
        dp[j][i]=min(dp[j][i],init+a[i]);
        st[i].push({init,j});
      }
    }
    cout<<dp[n][k];
    return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:35:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |       freopen("p1.inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~
blocks.cpp:36:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |       freopen("p1.out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("blocks.in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("blocks.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 13 ms 84304 KB Output is correct
3 Correct 12 ms 84048 KB Output is correct
4 Correct 12 ms 84048 KB Output is correct
5 Correct 13 ms 84060 KB Output is correct
6 Correct 12 ms 84048 KB Output is correct
7 Incorrect 12 ms 84048 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 12 ms 84048 KB Output is correct
3 Correct 12 ms 84048 KB Output is correct
4 Correct 12 ms 84048 KB Output is correct
5 Correct 13 ms 84048 KB Output is correct
6 Correct 13 ms 84056 KB Output is correct
7 Incorrect 13 ms 84048 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 13 ms 84304 KB Output is correct
3 Correct 12 ms 84048 KB Output is correct
4 Correct 12 ms 84048 KB Output is correct
5 Correct 13 ms 84060 KB Output is correct
6 Correct 12 ms 84048 KB Output is correct
7 Incorrect 12 ms 84048 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 13 ms 84304 KB Output is correct
3 Correct 12 ms 84048 KB Output is correct
4 Correct 12 ms 84048 KB Output is correct
5 Correct 13 ms 84060 KB Output is correct
6 Correct 12 ms 84048 KB Output is correct
7 Incorrect 12 ms 84048 KB Output isn't correct
8 Halted 0 ms 0 KB -