답안 #873943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873943 2023-11-16T05:14:00 Z 8pete8 K개의 묶음 (IZhO14_blocks) C++14
53 / 100
1000 ms 103892 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=1e6,inf=1e18;
int seg[mxn+10],n,dp[mxn+10][105],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 2 ms 16220 KB Output is correct
2 Correct 2 ms 16092 KB Output is correct
3 Correct 2 ms 16220 KB Output is correct
4 Correct 3 ms 16472 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 3 ms 16220 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 2 ms 16088 KB Output is correct
9 Correct 2 ms 16220 KB Output is correct
10 Correct 2 ms 16220 KB Output is correct
11 Correct 2 ms 16220 KB Output is correct
12 Correct 3 ms 16220 KB Output is correct
13 Correct 3 ms 16216 KB Output is correct
14 Correct 3 ms 16220 KB Output is correct
15 Correct 2 ms 16220 KB Output is correct
16 Correct 3 ms 16088 KB Output is correct
17 Correct 3 ms 16216 KB Output is correct
18 Correct 3 ms 16088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16220 KB Output is correct
2 Correct 3 ms 16216 KB Output is correct
3 Correct 2 ms 16220 KB Output is correct
4 Correct 2 ms 16088 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 3 ms 16220 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 3 ms 16220 KB Output is correct
9 Correct 3 ms 16084 KB Output is correct
10 Correct 2 ms 16216 KB Output is correct
11 Correct 2 ms 16220 KB Output is correct
12 Correct 3 ms 16220 KB Output is correct
13 Correct 3 ms 16096 KB Output is correct
14 Correct 3 ms 16220 KB Output is correct
15 Correct 3 ms 16220 KB Output is correct
16 Correct 3 ms 16220 KB Output is correct
17 Correct 3 ms 16220 KB Output is correct
18 Correct 3 ms 16216 KB Output is correct
19 Correct 3 ms 16220 KB Output is correct
20 Correct 3 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16220 KB Output is correct
2 Correct 2 ms 16092 KB Output is correct
3 Correct 2 ms 16220 KB Output is correct
4 Correct 3 ms 16472 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 3 ms 16220 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 2 ms 16088 KB Output is correct
9 Correct 2 ms 16220 KB Output is correct
10 Correct 2 ms 16220 KB Output is correct
11 Correct 2 ms 16220 KB Output is correct
12 Correct 3 ms 16220 KB Output is correct
13 Correct 3 ms 16216 KB Output is correct
14 Correct 3 ms 16220 KB Output is correct
15 Correct 2 ms 16220 KB Output is correct
16 Correct 3 ms 16088 KB Output is correct
17 Correct 3 ms 16216 KB Output is correct
18 Correct 3 ms 16088 KB Output is correct
19 Correct 3 ms 16220 KB Output is correct
20 Correct 3 ms 16216 KB Output is correct
21 Correct 2 ms 16220 KB Output is correct
22 Correct 2 ms 16088 KB Output is correct
23 Correct 3 ms 16220 KB Output is correct
24 Correct 3 ms 16220 KB Output is correct
25 Correct 3 ms 16220 KB Output is correct
26 Correct 3 ms 16220 KB Output is correct
27 Correct 3 ms 16084 KB Output is correct
28 Correct 2 ms 16216 KB Output is correct
29 Correct 2 ms 16220 KB Output is correct
30 Correct 3 ms 16220 KB Output is correct
31 Correct 3 ms 16096 KB Output is correct
32 Correct 3 ms 16220 KB Output is correct
33 Correct 3 ms 16220 KB Output is correct
34 Correct 3 ms 16220 KB Output is correct
35 Correct 3 ms 16220 KB Output is correct
36 Correct 3 ms 16216 KB Output is correct
37 Correct 3 ms 16220 KB Output is correct
38 Correct 3 ms 16220 KB Output is correct
39 Correct 3 ms 16220 KB Output is correct
40 Correct 3 ms 16220 KB Output is correct
41 Correct 3 ms 16472 KB Output is correct
42 Correct 3 ms 16220 KB Output is correct
43 Correct 3 ms 16096 KB Output is correct
44 Correct 3 ms 16216 KB Output is correct
45 Correct 2 ms 16220 KB Output is correct
46 Correct 3 ms 16220 KB Output is correct
47 Correct 3 ms 16080 KB Output is correct
48 Correct 2 ms 16220 KB Output is correct
49 Correct 3 ms 16220 KB Output is correct
50 Correct 3 ms 16220 KB Output is correct
51 Correct 3 ms 16220 KB Output is correct
52 Correct 3 ms 16220 KB Output is correct
53 Correct 3 ms 16220 KB Output is correct
54 Correct 3 ms 16216 KB Output is correct
55 Correct 3 ms 16216 KB Output is correct
56 Correct 3 ms 16224 KB Output is correct
57 Correct 3 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16220 KB Output is correct
2 Correct 2 ms 16092 KB Output is correct
3 Correct 2 ms 16220 KB Output is correct
4 Correct 3 ms 16472 KB Output is correct
5 Correct 3 ms 16220 KB Output is correct
6 Correct 3 ms 16220 KB Output is correct
7 Correct 3 ms 16220 KB Output is correct
8 Correct 2 ms 16088 KB Output is correct
9 Correct 2 ms 16220 KB Output is correct
10 Correct 2 ms 16220 KB Output is correct
11 Correct 2 ms 16220 KB Output is correct
12 Correct 3 ms 16220 KB Output is correct
13 Correct 3 ms 16216 KB Output is correct
14 Correct 3 ms 16220 KB Output is correct
15 Correct 2 ms 16220 KB Output is correct
16 Correct 3 ms 16088 KB Output is correct
17 Correct 3 ms 16216 KB Output is correct
18 Correct 3 ms 16088 KB Output is correct
19 Correct 3 ms 16220 KB Output is correct
20 Correct 3 ms 16216 KB Output is correct
21 Correct 2 ms 16220 KB Output is correct
22 Correct 2 ms 16088 KB Output is correct
23 Correct 3 ms 16220 KB Output is correct
24 Correct 3 ms 16220 KB Output is correct
25 Correct 3 ms 16220 KB Output is correct
26 Correct 3 ms 16220 KB Output is correct
27 Correct 3 ms 16084 KB Output is correct
28 Correct 2 ms 16216 KB Output is correct
29 Correct 2 ms 16220 KB Output is correct
30 Correct 3 ms 16220 KB Output is correct
31 Correct 3 ms 16096 KB Output is correct
32 Correct 3 ms 16220 KB Output is correct
33 Correct 3 ms 16220 KB Output is correct
34 Correct 3 ms 16220 KB Output is correct
35 Correct 3 ms 16220 KB Output is correct
36 Correct 3 ms 16216 KB Output is correct
37 Correct 3 ms 16220 KB Output is correct
38 Correct 3 ms 16220 KB Output is correct
39 Correct 3 ms 16220 KB Output is correct
40 Correct 3 ms 16220 KB Output is correct
41 Correct 3 ms 16472 KB Output is correct
42 Correct 3 ms 16220 KB Output is correct
43 Correct 3 ms 16096 KB Output is correct
44 Correct 3 ms 16216 KB Output is correct
45 Correct 2 ms 16220 KB Output is correct
46 Correct 3 ms 16220 KB Output is correct
47 Correct 3 ms 16080 KB Output is correct
48 Correct 2 ms 16220 KB Output is correct
49 Correct 3 ms 16220 KB Output is correct
50 Correct 3 ms 16220 KB Output is correct
51 Correct 3 ms 16220 KB Output is correct
52 Correct 3 ms 16220 KB Output is correct
53 Correct 3 ms 16220 KB Output is correct
54 Correct 3 ms 16216 KB Output is correct
55 Correct 3 ms 16216 KB Output is correct
56 Correct 3 ms 16224 KB Output is correct
57 Correct 3 ms 16220 KB Output is correct
58 Correct 27 ms 24740 KB Output is correct
59 Correct 15 ms 56032 KB Output is correct
60 Correct 41 ms 56032 KB Output is correct
61 Correct 339 ms 56228 KB Output is correct
62 Execution timed out 1052 ms 103892 KB Time limit exceeded
63 Halted 0 ms 0 KB -