Submission #93983

# Submission time Handle Problem Language Result Execution time Memory
93983 2019-01-13T20:44:03 Z kjain_1810 K blocks (IZhO14_blocks) C++17
53 / 100
3 ms 380 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

using namespace std;

const int N=105;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

ll n, k, arr[N], dp[N][N];

ll solve(ll i, ll j)
{
    if(j==0)
        if(i==n+1)
            return 0;
        else
            return 1e15;
    if(i==n+1)
        return 1e15;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll ret=1e15;
    ll maxi=0;
    for(ll b=i; b<=n; b++)
    {
        maxi=max(maxi, arr[b]);
        ret=min(ret, solve(b+1, j-1)+maxi);
    }
    return dp[i][j]=ret;
}

int main() 
{
    inlld2(n, k);
    for(ll a=1; a<=n; a++)
        inlld(arr[a]);
    for(ll j=0; j<=k; j++)
        for(ll i=n+1; i>=1; i--)
        {
            if(j==0)
                if(i==n+1)
                    dp[i][j]=0;
                else
                    dp[i][j]=1e15;
            else if(i==n+1)
                dp[i][j]=1e15;
            else
            {
                dp[i][j]=1e15;
                ll maxi=0;
                for(ll a=i; a<=n; a++)
                {
                    maxi=max(maxi, arr[a]);
                    dp[i][j]=min(dp[i][j], dp[a+1][j-1]+maxi);
                }
            }
        }
    printf("%lld\n", dp[1][k]);
    // memset(dp, -1, sizeof(dp));
    // printf("%lld\n", solve(1, k));
    return 0;
}

Compilation message

blocks.cpp: In function 'll solve(ll, ll)':
blocks.cpp:24:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
     if(j==0)
       ^
blocks.cpp: In function 'int main()':
blocks.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define inlld2(a, b) scanf("%lld%lld", &a, &b)
                      ~~~~~^~~~~~~~~~~~~~~~~~~~
blocks.cpp:45:5: note: in expansion of macro 'inlld2'
     inlld2(n, k);
     ^~~~~~
blocks.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define inlld(a) scanf("%lld", &a)
                  ~~~~~^~~~~~~~~~~~
blocks.cpp:47:9: note: in expansion of macro 'inlld'
         inlld(arr[a]);
         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 252 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2 ms 256 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -