답안 #873942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873942 2023-11-16T05:12:55 Z 8pete8 K개의 묶음 (IZhO14_blocks) C++14
53 / 100
341 ms 41476 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>  
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
#define double long double
const int mxn=1e5,inf=1e18;
int seg[mxn+10],n,dp[mxn+10][101],l[mxn+10],r[mxn+10],v[mxn+10],k;
int qry(int l,int r){
    int ans=inf;
    for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
        if(l&1)ans=min(ans,seg[l++]);
        if(!(r&1))ans=min(ans,seg[r--]);
    }
    return ans;
}
void build(){for(int i=n-1;i>=0;i--)seg[i]=min(seg[i<<1],seg[(i<<1)^1]);}
int32_t main(){
    fastio
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>v[i];
    v[0]=-1e18;
    stack<int>st;
    n++;
    for(int i=1;i<n;i++){
        while(!st.empty()&&v[st.top()]<=v[i])st.pop();
        if(!st.empty())l[i]=st.top();
        else l[i]=0;
        st.push(i);
    }
    while(!st.empty())st.pop();
    for(int i=n-1;i>=1;i--){
        while(!st.empty()&&v[st.top()]<=v[i])st.pop();
        if(!st.empty())r[i]=st.top();
        else r[i]=n;
        st.push(i);
    }
    fill(seg,seg+mxn+5,inf);
    seg[n]=0;
    build();
    for(int j=1;j<=k;j++){
        priority_queue<pii,vector<pii>,greater<pii>>pq;
        for(int i=0;i<n;i++)dp[i][j]=inf;
        for(int i=j;i<n;i++){
            int g=qry(l[i],i-1);
            g+=v[i];
            pq.push({g,r[i]});
            while(!pq.empty()&&(pq.top().s<=i))pq.pop();
            if(!pq.empty())dp[i][j]=pq.top().f;
        }
        for(int i=0;i<n;i++)seg[i+n]=dp[i][j];
        build();
    }
    cout<<dp[n-1][k];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5324 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 1 ms 5208 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5464 KB Output is correct
12 Correct 1 ms 5212 KB Output is correct
13 Correct 1 ms 5208 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
15 Correct 1 ms 5212 KB Output is correct
16 Correct 1 ms 5212 KB Output is correct
17 Correct 1 ms 5332 KB Output is correct
18 Correct 1 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5328 KB Output is correct
6 Correct 1 ms 5208 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5332 KB Output is correct
12 Correct 1 ms 5332 KB Output is correct
13 Correct 1 ms 5212 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
15 Correct 1 ms 5204 KB Output is correct
16 Correct 1 ms 5212 KB Output is correct
17 Correct 1 ms 5328 KB Output is correct
18 Correct 1 ms 5304 KB Output is correct
19 Correct 1 ms 5212 KB Output is correct
20 Correct 1 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5324 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 1 ms 5208 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5464 KB Output is correct
12 Correct 1 ms 5212 KB Output is correct
13 Correct 1 ms 5208 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
15 Correct 1 ms 5212 KB Output is correct
16 Correct 1 ms 5212 KB Output is correct
17 Correct 1 ms 5332 KB Output is correct
18 Correct 1 ms 5212 KB Output is correct
19 Correct 1 ms 5208 KB Output is correct
20 Correct 1 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 1 ms 5212 KB Output is correct
23 Correct 1 ms 5328 KB Output is correct
24 Correct 1 ms 5208 KB Output is correct
25 Correct 1 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 1 ms 5212 KB Output is correct
28 Correct 1 ms 5212 KB Output is correct
29 Correct 1 ms 5332 KB Output is correct
30 Correct 1 ms 5332 KB Output is correct
31 Correct 1 ms 5212 KB Output is correct
32 Correct 1 ms 5212 KB Output is correct
33 Correct 1 ms 5204 KB Output is correct
34 Correct 1 ms 5212 KB Output is correct
35 Correct 1 ms 5328 KB Output is correct
36 Correct 1 ms 5304 KB Output is correct
37 Correct 1 ms 5212 KB Output is correct
38 Correct 1 ms 5328 KB Output is correct
39 Correct 1 ms 5212 KB Output is correct
40 Correct 1 ms 5212 KB Output is correct
41 Correct 1 ms 5212 KB Output is correct
42 Correct 1 ms 5212 KB Output is correct
43 Correct 1 ms 5212 KB Output is correct
44 Correct 1 ms 5212 KB Output is correct
45 Correct 1 ms 5212 KB Output is correct
46 Correct 1 ms 5212 KB Output is correct
47 Correct 1 ms 5212 KB Output is correct
48 Correct 1 ms 5212 KB Output is correct
49 Correct 1 ms 5332 KB Output is correct
50 Correct 1 ms 5212 KB Output is correct
51 Correct 1 ms 5220 KB Output is correct
52 Correct 1 ms 5408 KB Output is correct
53 Correct 1 ms 5212 KB Output is correct
54 Correct 1 ms 5212 KB Output is correct
55 Correct 2 ms 5212 KB Output is correct
56 Correct 2 ms 5464 KB Output is correct
57 Correct 1 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 1 ms 5212 KB Output is correct
3 Correct 1 ms 5324 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 1 ms 5208 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 1 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 1 ms 5212 KB Output is correct
11 Correct 1 ms 5464 KB Output is correct
12 Correct 1 ms 5212 KB Output is correct
13 Correct 1 ms 5208 KB Output is correct
14 Correct 1 ms 5212 KB Output is correct
15 Correct 1 ms 5212 KB Output is correct
16 Correct 1 ms 5212 KB Output is correct
17 Correct 1 ms 5332 KB Output is correct
18 Correct 1 ms 5212 KB Output is correct
19 Correct 1 ms 5208 KB Output is correct
20 Correct 1 ms 5212 KB Output is correct
21 Correct 2 ms 5212 KB Output is correct
22 Correct 1 ms 5212 KB Output is correct
23 Correct 1 ms 5328 KB Output is correct
24 Correct 1 ms 5208 KB Output is correct
25 Correct 1 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 1 ms 5212 KB Output is correct
28 Correct 1 ms 5212 KB Output is correct
29 Correct 1 ms 5332 KB Output is correct
30 Correct 1 ms 5332 KB Output is correct
31 Correct 1 ms 5212 KB Output is correct
32 Correct 1 ms 5212 KB Output is correct
33 Correct 1 ms 5204 KB Output is correct
34 Correct 1 ms 5212 KB Output is correct
35 Correct 1 ms 5328 KB Output is correct
36 Correct 1 ms 5304 KB Output is correct
37 Correct 1 ms 5212 KB Output is correct
38 Correct 1 ms 5328 KB Output is correct
39 Correct 1 ms 5212 KB Output is correct
40 Correct 1 ms 5212 KB Output is correct
41 Correct 1 ms 5212 KB Output is correct
42 Correct 1 ms 5212 KB Output is correct
43 Correct 1 ms 5212 KB Output is correct
44 Correct 1 ms 5212 KB Output is correct
45 Correct 1 ms 5212 KB Output is correct
46 Correct 1 ms 5212 KB Output is correct
47 Correct 1 ms 5212 KB Output is correct
48 Correct 1 ms 5212 KB Output is correct
49 Correct 1 ms 5332 KB Output is correct
50 Correct 1 ms 5212 KB Output is correct
51 Correct 1 ms 5220 KB Output is correct
52 Correct 1 ms 5408 KB Output is correct
53 Correct 1 ms 5212 KB Output is correct
54 Correct 1 ms 5212 KB Output is correct
55 Correct 2 ms 5212 KB Output is correct
56 Correct 2 ms 5464 KB Output is correct
57 Correct 1 ms 5212 KB Output is correct
58 Correct 25 ms 11864 KB Output is correct
59 Correct 18 ms 41440 KB Output is correct
60 Correct 38 ms 41476 KB Output is correct
61 Correct 341 ms 41424 KB Output is correct
62 Runtime error 19 ms 12124 KB Execution killed with signal 11
63 Halted 0 ms 0 KB -