Submission #1101507

# Submission time Handle Problem Language Result Execution time Memory
1101507 2024-10-16T09:15:17 Z tuan19a K blocks (IZhO14_blocks) C++14
53 / 100
4 ms 8536 KB
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define el "\n"
#define FILE "test1"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define bit(mask,i) ((mask>>i) & 1)
const int N=1e4+2;
const ll oo=1e18;
const int mod=1e9+7;
const int base=31;
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
using namespace std;

int n,k,a[N],dp[N][102];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    if (fopen(FILE".inp","r"))
    {
      freopen(FILE".inp","r",stdin);
      freopen(FILE".out","w",stdout);
    }

    cin>>n>>k;
    for (int i=1;i<=n;i++)
        cin>>a[i];

    memset(dp,0x3f,sizeof dp);

    dp[0][1]=0;
    for (int i=1;i<=n;i++) dp[i][1]=max(dp[i-1][1],a[i]);

    for (int i=2;i<=k;i++)
      {
          stack <pii> s;
          for (int j=i;j<=n;j++)
          {
              int minn=dp[j-1][i-1];
              while (!s.empty() && a[j]>=a[s.top().se]) minn=min(minn,s.top().fi),s.pop();
              int pos=0;
              if (!s.empty()) pos=s.top().se;
              dp[j][i]=min(dp[pos][i],minn+a[j]);
              s.push({minn,j});
          }
      }
    cout<<dp[n][k];
}
/**  /\_/\
 *  (= ._.)
 *  / >AC \>AC
**/

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:27:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |       freopen(FILE".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:28:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |       freopen(FILE".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 2 ms 8272 KB Output is correct
4 Correct 3 ms 8272 KB Output is correct
5 Correct 2 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 2 ms 8272 KB Output is correct
8 Correct 2 ms 8272 KB Output is correct
9 Correct 2 ms 8272 KB Output is correct
10 Correct 2 ms 8272 KB Output is correct
11 Correct 3 ms 8272 KB Output is correct
12 Correct 2 ms 8272 KB Output is correct
13 Correct 2 ms 8448 KB Output is correct
14 Correct 2 ms 8272 KB Output is correct
15 Correct 2 ms 8440 KB Output is correct
16 Correct 2 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 2 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8368 KB Output is correct
2 Correct 2 ms 8444 KB Output is correct
3 Correct 3 ms 8272 KB Output is correct
4 Correct 2 ms 8272 KB Output is correct
5 Correct 2 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 3 ms 8272 KB Output is correct
8 Correct 2 ms 8272 KB Output is correct
9 Correct 3 ms 8272 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 2 ms 8272 KB Output is correct
13 Correct 2 ms 8272 KB Output is correct
14 Correct 2 ms 8272 KB Output is correct
15 Correct 3 ms 8272 KB Output is correct
16 Correct 2 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 2 ms 8272 KB Output is correct
19 Correct 2 ms 8344 KB Output is correct
20 Correct 3 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 2 ms 8272 KB Output is correct
4 Correct 3 ms 8272 KB Output is correct
5 Correct 2 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 2 ms 8272 KB Output is correct
8 Correct 2 ms 8272 KB Output is correct
9 Correct 2 ms 8272 KB Output is correct
10 Correct 2 ms 8272 KB Output is correct
11 Correct 3 ms 8272 KB Output is correct
12 Correct 2 ms 8272 KB Output is correct
13 Correct 2 ms 8448 KB Output is correct
14 Correct 2 ms 8272 KB Output is correct
15 Correct 2 ms 8440 KB Output is correct
16 Correct 2 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 2 ms 8272 KB Output is correct
19 Correct 2 ms 8368 KB Output is correct
20 Correct 2 ms 8444 KB Output is correct
21 Correct 3 ms 8272 KB Output is correct
22 Correct 2 ms 8272 KB Output is correct
23 Correct 2 ms 8272 KB Output is correct
24 Correct 3 ms 8272 KB Output is correct
25 Correct 3 ms 8272 KB Output is correct
26 Correct 2 ms 8272 KB Output is correct
27 Correct 3 ms 8272 KB Output is correct
28 Correct 3 ms 8272 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 2 ms 8272 KB Output is correct
31 Correct 2 ms 8272 KB Output is correct
32 Correct 2 ms 8272 KB Output is correct
33 Correct 3 ms 8272 KB Output is correct
34 Correct 2 ms 8272 KB Output is correct
35 Correct 3 ms 8272 KB Output is correct
36 Correct 2 ms 8272 KB Output is correct
37 Correct 2 ms 8344 KB Output is correct
38 Correct 3 ms 8272 KB Output is correct
39 Correct 3 ms 8272 KB Output is correct
40 Correct 3 ms 8272 KB Output is correct
41 Correct 3 ms 8272 KB Output is correct
42 Correct 3 ms 8280 KB Output is correct
43 Correct 2 ms 8272 KB Output is correct
44 Correct 2 ms 8256 KB Output is correct
45 Correct 3 ms 8440 KB Output is correct
46 Correct 2 ms 8272 KB Output is correct
47 Correct 2 ms 8284 KB Output is correct
48 Correct 2 ms 8272 KB Output is correct
49 Correct 2 ms 8272 KB Output is correct
50 Correct 3 ms 8272 KB Output is correct
51 Correct 3 ms 8272 KB Output is correct
52 Correct 2 ms 8272 KB Output is correct
53 Correct 2 ms 8272 KB Output is correct
54 Correct 2 ms 8452 KB Output is correct
55 Correct 3 ms 8440 KB Output is correct
56 Correct 2 ms 8272 KB Output is correct
57 Correct 2 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8272 KB Output is correct
2 Correct 2 ms 8272 KB Output is correct
3 Correct 2 ms 8272 KB Output is correct
4 Correct 3 ms 8272 KB Output is correct
5 Correct 2 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 2 ms 8272 KB Output is correct
8 Correct 2 ms 8272 KB Output is correct
9 Correct 2 ms 8272 KB Output is correct
10 Correct 2 ms 8272 KB Output is correct
11 Correct 3 ms 8272 KB Output is correct
12 Correct 2 ms 8272 KB Output is correct
13 Correct 2 ms 8448 KB Output is correct
14 Correct 2 ms 8272 KB Output is correct
15 Correct 2 ms 8440 KB Output is correct
16 Correct 2 ms 8272 KB Output is correct
17 Correct 3 ms 8272 KB Output is correct
18 Correct 2 ms 8272 KB Output is correct
19 Correct 2 ms 8368 KB Output is correct
20 Correct 2 ms 8444 KB Output is correct
21 Correct 3 ms 8272 KB Output is correct
22 Correct 2 ms 8272 KB Output is correct
23 Correct 2 ms 8272 KB Output is correct
24 Correct 3 ms 8272 KB Output is correct
25 Correct 3 ms 8272 KB Output is correct
26 Correct 2 ms 8272 KB Output is correct
27 Correct 3 ms 8272 KB Output is correct
28 Correct 3 ms 8272 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 2 ms 8272 KB Output is correct
31 Correct 2 ms 8272 KB Output is correct
32 Correct 2 ms 8272 KB Output is correct
33 Correct 3 ms 8272 KB Output is correct
34 Correct 2 ms 8272 KB Output is correct
35 Correct 3 ms 8272 KB Output is correct
36 Correct 2 ms 8272 KB Output is correct
37 Correct 2 ms 8344 KB Output is correct
38 Correct 3 ms 8272 KB Output is correct
39 Correct 3 ms 8272 KB Output is correct
40 Correct 3 ms 8272 KB Output is correct
41 Correct 3 ms 8272 KB Output is correct
42 Correct 3 ms 8280 KB Output is correct
43 Correct 2 ms 8272 KB Output is correct
44 Correct 2 ms 8256 KB Output is correct
45 Correct 3 ms 8440 KB Output is correct
46 Correct 2 ms 8272 KB Output is correct
47 Correct 2 ms 8284 KB Output is correct
48 Correct 2 ms 8272 KB Output is correct
49 Correct 2 ms 8272 KB Output is correct
50 Correct 3 ms 8272 KB Output is correct
51 Correct 3 ms 8272 KB Output is correct
52 Correct 2 ms 8272 KB Output is correct
53 Correct 2 ms 8272 KB Output is correct
54 Correct 2 ms 8452 KB Output is correct
55 Correct 3 ms 8440 KB Output is correct
56 Correct 2 ms 8272 KB Output is correct
57 Correct 2 ms 8272 KB Output is correct
58 Correct 4 ms 8520 KB Output is correct
59 Runtime error 2 ms 592 KB Execution killed with signal 11
60 Halted 0 ms 0 KB -