답안 #1104995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104995 2024-10-25T05:29:42 Z dophu K개의 묶음 (IZhO14_blocks) C++17
100 / 100
160 ms 164948 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);
   /// for (ll i=1;i<=n;i++) cout<<dp[i][1]<<' ';
  ///  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()) {
          dp[j][i]=dp[st[i].top().second][i];
        }
        dp[j][i]=min(dp[j][i],init+a[j]);
        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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 13 ms 84036 KB Output is correct
3 Correct 11 ms 84048 KB Output is correct
4 Correct 14 ms 84016 KB Output is correct
5 Correct 13 ms 84048 KB Output is correct
6 Correct 14 ms 84036 KB Output is correct
7 Correct 13 ms 84048 KB Output is correct
8 Correct 12 ms 84048 KB Output is correct
9 Correct 11 ms 84216 KB Output is correct
10 Correct 13 ms 84048 KB Output is correct
11 Correct 12 ms 84048 KB Output is correct
12 Correct 12 ms 84244 KB Output is correct
13 Correct 12 ms 84216 KB Output is correct
14 Correct 13 ms 84240 KB Output is correct
15 Correct 13 ms 84304 KB Output is correct
16 Correct 13 ms 84048 KB Output is correct
17 Correct 12 ms 84128 KB Output is correct
18 Correct 12 ms 84048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 84060 KB Output is correct
2 Correct 13 ms 84048 KB Output is correct
3 Correct 14 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 14 ms 84048 KB Output is correct
7 Correct 12 ms 84048 KB Output is correct
8 Correct 14 ms 84240 KB Output is correct
9 Correct 12 ms 84048 KB Output is correct
10 Correct 12 ms 84048 KB Output is correct
11 Correct 11 ms 84048 KB Output is correct
12 Correct 11 ms 84016 KB Output is correct
13 Correct 13 ms 84244 KB Output is correct
14 Correct 12 ms 84048 KB Output is correct
15 Correct 13 ms 84248 KB Output is correct
16 Correct 12 ms 84048 KB Output is correct
17 Correct 11 ms 84048 KB Output is correct
18 Correct 11 ms 84048 KB Output is correct
19 Correct 12 ms 84048 KB Output is correct
20 Correct 11 ms 84048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 13 ms 84036 KB Output is correct
3 Correct 11 ms 84048 KB Output is correct
4 Correct 14 ms 84016 KB Output is correct
5 Correct 13 ms 84048 KB Output is correct
6 Correct 14 ms 84036 KB Output is correct
7 Correct 13 ms 84048 KB Output is correct
8 Correct 12 ms 84048 KB Output is correct
9 Correct 11 ms 84216 KB Output is correct
10 Correct 13 ms 84048 KB Output is correct
11 Correct 12 ms 84048 KB Output is correct
12 Correct 12 ms 84244 KB Output is correct
13 Correct 12 ms 84216 KB Output is correct
14 Correct 13 ms 84240 KB Output is correct
15 Correct 13 ms 84304 KB Output is correct
16 Correct 13 ms 84048 KB Output is correct
17 Correct 12 ms 84128 KB Output is correct
18 Correct 12 ms 84048 KB Output is correct
19 Correct 12 ms 84060 KB Output is correct
20 Correct 13 ms 84048 KB Output is correct
21 Correct 14 ms 84048 KB Output is correct
22 Correct 12 ms 84048 KB Output is correct
23 Correct 13 ms 84048 KB Output is correct
24 Correct 14 ms 84048 KB Output is correct
25 Correct 12 ms 84048 KB Output is correct
26 Correct 14 ms 84240 KB Output is correct
27 Correct 12 ms 84048 KB Output is correct
28 Correct 12 ms 84048 KB Output is correct
29 Correct 11 ms 84048 KB Output is correct
30 Correct 11 ms 84016 KB Output is correct
31 Correct 13 ms 84244 KB Output is correct
32 Correct 12 ms 84048 KB Output is correct
33 Correct 13 ms 84248 KB Output is correct
34 Correct 12 ms 84048 KB Output is correct
35 Correct 11 ms 84048 KB Output is correct
36 Correct 11 ms 84048 KB Output is correct
37 Correct 12 ms 84048 KB Output is correct
38 Correct 11 ms 84048 KB Output is correct
39 Correct 13 ms 84048 KB Output is correct
40 Correct 14 ms 84252 KB Output is correct
41 Correct 13 ms 84048 KB Output is correct
42 Correct 12 ms 84048 KB Output is correct
43 Correct 11 ms 84048 KB Output is correct
44 Correct 12 ms 84048 KB Output is correct
45 Correct 12 ms 84048 KB Output is correct
46 Correct 12 ms 84048 KB Output is correct
47 Correct 13 ms 84048 KB Output is correct
48 Correct 13 ms 84060 KB Output is correct
49 Correct 13 ms 84048 KB Output is correct
50 Correct 11 ms 84048 KB Output is correct
51 Correct 12 ms 84048 KB Output is correct
52 Correct 13 ms 84032 KB Output is correct
53 Correct 14 ms 84060 KB Output is correct
54 Correct 13 ms 84128 KB Output is correct
55 Correct 13 ms 84048 KB Output is correct
56 Correct 13 ms 84048 KB Output is correct
57 Correct 12 ms 84048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 84048 KB Output is correct
2 Correct 13 ms 84036 KB Output is correct
3 Correct 11 ms 84048 KB Output is correct
4 Correct 14 ms 84016 KB Output is correct
5 Correct 13 ms 84048 KB Output is correct
6 Correct 14 ms 84036 KB Output is correct
7 Correct 13 ms 84048 KB Output is correct
8 Correct 12 ms 84048 KB Output is correct
9 Correct 11 ms 84216 KB Output is correct
10 Correct 13 ms 84048 KB Output is correct
11 Correct 12 ms 84048 KB Output is correct
12 Correct 12 ms 84244 KB Output is correct
13 Correct 12 ms 84216 KB Output is correct
14 Correct 13 ms 84240 KB Output is correct
15 Correct 13 ms 84304 KB Output is correct
16 Correct 13 ms 84048 KB Output is correct
17 Correct 12 ms 84128 KB Output is correct
18 Correct 12 ms 84048 KB Output is correct
19 Correct 12 ms 84060 KB Output is correct
20 Correct 13 ms 84048 KB Output is correct
21 Correct 14 ms 84048 KB Output is correct
22 Correct 12 ms 84048 KB Output is correct
23 Correct 13 ms 84048 KB Output is correct
24 Correct 14 ms 84048 KB Output is correct
25 Correct 12 ms 84048 KB Output is correct
26 Correct 14 ms 84240 KB Output is correct
27 Correct 12 ms 84048 KB Output is correct
28 Correct 12 ms 84048 KB Output is correct
29 Correct 11 ms 84048 KB Output is correct
30 Correct 11 ms 84016 KB Output is correct
31 Correct 13 ms 84244 KB Output is correct
32 Correct 12 ms 84048 KB Output is correct
33 Correct 13 ms 84248 KB Output is correct
34 Correct 12 ms 84048 KB Output is correct
35 Correct 11 ms 84048 KB Output is correct
36 Correct 11 ms 84048 KB Output is correct
37 Correct 12 ms 84048 KB Output is correct
38 Correct 11 ms 84048 KB Output is correct
39 Correct 13 ms 84048 KB Output is correct
40 Correct 14 ms 84252 KB Output is correct
41 Correct 13 ms 84048 KB Output is correct
42 Correct 12 ms 84048 KB Output is correct
43 Correct 11 ms 84048 KB Output is correct
44 Correct 12 ms 84048 KB Output is correct
45 Correct 12 ms 84048 KB Output is correct
46 Correct 12 ms 84048 KB Output is correct
47 Correct 13 ms 84048 KB Output is correct
48 Correct 13 ms 84060 KB Output is correct
49 Correct 13 ms 84048 KB Output is correct
50 Correct 11 ms 84048 KB Output is correct
51 Correct 12 ms 84048 KB Output is correct
52 Correct 13 ms 84032 KB Output is correct
53 Correct 14 ms 84060 KB Output is correct
54 Correct 13 ms 84128 KB Output is correct
55 Correct 13 ms 84048 KB Output is correct
56 Correct 13 ms 84048 KB Output is correct
57 Correct 12 ms 84048 KB Output is correct
58 Correct 14 ms 86364 KB Output is correct
59 Correct 17 ms 97020 KB Output is correct
60 Correct 19 ms 96636 KB Output is correct
61 Correct 46 ms 96848 KB Output is correct
62 Correct 114 ms 107344 KB Output is correct
63 Correct 24 ms 107300 KB Output is correct
64 Correct 62 ms 107344 KB Output is correct
65 Correct 11 ms 84048 KB Output is correct
66 Correct 11 ms 84048 KB Output is correct
67 Correct 11 ms 84024 KB Output is correct
68 Correct 12 ms 84044 KB Output is correct
69 Correct 11 ms 84048 KB Output is correct
70 Correct 11 ms 84048 KB Output is correct
71 Correct 23 ms 86376 KB Output is correct
72 Correct 13 ms 86352 KB Output is correct
73 Correct 14 ms 86352 KB Output is correct
74 Correct 16 ms 96848 KB Output is correct
75 Correct 19 ms 96864 KB Output is correct
76 Correct 53 ms 96848 KB Output is correct
77 Correct 135 ms 107344 KB Output is correct
78 Correct 25 ms 107344 KB Output is correct
79 Correct 74 ms 107484 KB Output is correct
80 Correct 26 ms 107344 KB Output is correct
81 Correct 34 ms 107404 KB Output is correct
82 Correct 134 ms 107360 KB Output is correct
83 Correct 12 ms 84244 KB Output is correct
84 Correct 11 ms 84304 KB Output is correct
85 Correct 25 ms 92008 KB Output is correct
86 Correct 12 ms 86372 KB Output is correct
87 Correct 15 ms 87632 KB Output is correct
88 Correct 16 ms 96848 KB Output is correct
89 Correct 20 ms 98384 KB Output is correct
90 Correct 63 ms 116388 KB Output is correct
91 Correct 160 ms 164948 KB Output is correct
92 Correct 40 ms 108616 KB Output is correct
93 Correct 96 ms 132940 KB Output is correct
94 Correct 14 ms 86364 KB Output is correct
95 Correct 22 ms 86364 KB Output is correct
96 Correct 13 ms 84048 KB Output is correct
97 Correct 13 ms 84048 KB Output is correct
98 Correct 12 ms 84248 KB Output is correct
99 Correct 12 ms 84012 KB Output is correct