Submission #290395

# Submission time Handle Problem Language Result Execution time Memory
290395 2020-09-03T17:51:02 Z Dymo K blocks (IZhO14_blocks) C++14
100 / 100
325 ms 96488 KB
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define all(n) n.begin(),n.end()
#define endl "\n"
#define pll pair<ll,ll>
#define ff first
#define ss second
using namespace std;
const ll maxn=2e5+500;
const ll mod=1e9+7 ;
const ll base=500;
/// con 9 ngay

ll a[maxn];
ll dp[maxn][120];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    if (fopen("Farm.INP","r"))
    {
        freopen("Farm.INP","r",stdin);
        freopen("Farm.OUT","w",stdout);
    }
    ll n, k;
     cin>> n>> k;
     for (int i=1;i<=n;i++)
     {
       cin>>a[i];
     }
     for (int i=0;i<=n;i++)
     {
         for (int j=1;j<=k;j++)
         {
             dp[i][j]=1e15;

         }
     }
     dp[0][1]=1e15;
     for (int i=1;i<=n;i++)
     {
         if (i!=1) dp[i][1]=max(dp[i-1][1],a[i]);
         else dp[i][1]=a[i];
     }
     for (int j=2;j<=k;j++)
     {
         stack<pll> st;

         for (int i=j;i<=n;i++)
         {
             ll nw=dp[i-1][j-1];
             while (st.size()&&a[st.top().ss]<=a[i])
             {
                 nw=min(nw,st.top().ff);

                 st.pop();
             }
             ll t;
             if (st.size()) t=st.top().ss;
             else t=0;
             dp[i][j]=min(nw+a[i],dp[t][j]);
             st.push(make_pair(nw,i));
         }
     }
     cout <<dp[n][k];



}










Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |         freopen("Farm.INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         freopen("Farm.OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 396 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9856 KB Output is correct
2 Correct 25 ms 42744 KB Output is correct
3 Correct 29 ms 42752 KB Output is correct
4 Correct 86 ms 42744 KB Output is correct
5 Correct 290 ms 95864 KB Output is correct
6 Correct 59 ms 95864 KB Output is correct
7 Correct 160 ms 95736 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 1280 KB Output is correct
13 Correct 1 ms 1280 KB Output is correct
14 Correct 24 ms 9856 KB Output is correct
15 Correct 7 ms 9856 KB Output is correct
16 Correct 11 ms 9856 KB Output is correct
17 Correct 25 ms 42752 KB Output is correct
18 Correct 31 ms 42788 KB Output is correct
19 Correct 93 ms 42744 KB Output is correct
20 Correct 308 ms 95864 KB Output is correct
21 Correct 59 ms 95736 KB Output is correct
22 Correct 166 ms 95736 KB Output is correct
23 Correct 56 ms 95736 KB Output is correct
24 Correct 77 ms 95640 KB Output is correct
25 Correct 305 ms 95864 KB Output is correct
26 Correct 1 ms 1280 KB Output is correct
27 Correct 1 ms 1280 KB Output is correct
28 Correct 23 ms 9984 KB Output is correct
29 Correct 6 ms 9984 KB Output is correct
30 Correct 10 ms 9984 KB Output is correct
31 Correct 24 ms 42752 KB Output is correct
32 Correct 32 ms 43008 KB Output is correct
33 Correct 101 ms 43116 KB Output is correct
34 Correct 325 ms 96488 KB Output is correct
35 Correct 59 ms 96304 KB Output is correct
36 Correct 178 ms 96380 KB Output is correct
37 Correct 6 ms 9856 KB Output is correct
38 Correct 21 ms 9856 KB Output is correct
39 Correct 2 ms 1280 KB Output is correct
40 Correct 1 ms 1280 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct