Submission #37907

# Submission time Handle Problem Language Result Execution time Memory
37907 2017-12-29T02:32:33 Z mirbek01 K blocks (IZhO14_blocks) C++14
0 / 100
1000 ms 82880 KB
# include <bits/stdc++.h>

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e5 + 5;

typedef long long ll;

int n, a[N], k, t[N * 4];
ll dp[101][N];

void build(int v = 1, int tl = 1, int tr = n)
{
      if(tl == tr)
            t[v] = a[tl];
      else
      {
            int tm = (tl + tr) >> 1;
            build(v << 1, tl, tm);
            build((v << 1) | 1, tm + 1, tr);
            t[v] = max(t[v << 1], t[(v << 1) | 1]);
      }
}

int get(int l, int r, int v = 1, int tl = 1, int tr = n)
{
      if(l > tr || tl > r) return 0;
      if(l <= tl && tr <= r) return t[v];
      int tm = (tl + tr) >> 1;
      return max(get(l, r, v << 1, tl, tm),
                        get(l, r, (v << 1) | 1, tm + 1, tr));
}

void dv(int k, int l, int r, int opl, int opr)
{
      if(l > r) return ;

      int md = (l + r) >> 1, opt;

      dp[k][md] = 1e18;

      for(int i = opl; i <= min(md, opr); i ++)
      {
            ll now = dp[k - 1][i - 1] + get(i, md);
            if(now <= dp[k][md])
            {
                  dp[k][md] = now;
                  opt = i;
            }
      }

      dv(k, l, md - 1, opl, opt);
      dv(k, md + 1, r, opt, opr);
}

int main()
{
      cin >> n >> k;

      for(int i = 1; i <= n; i ++)
            scanf("%d", &a[i]);

      int mx = 0;
      build();

      for(int i = 1; i <= n; i ++)
      {
            mx = max(mx, a[i]);
            dp[1][i] = mx;
      }

      for(int i = 2; i <= k; i ++)
            dv(i, i, n, i, n);

      cout << dp[k][n] << endl;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:67:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i]);
                               ^
blocks.cpp: In function 'void dv(int, int, int, int, int)':
blocks.cpp:58:33: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
       dv(k, l, md - 1, opl, opt);
                                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 82880 KB Output is correct
2 Correct 0 ms 82880 KB Output is correct
3 Correct 0 ms 82880 KB Output is correct
4 Correct 0 ms 82880 KB Output is correct
5 Correct 0 ms 82880 KB Output is correct
6 Correct 0 ms 82880 KB Output is correct
7 Correct 0 ms 82880 KB Output is correct
8 Correct 0 ms 82880 KB Output is correct
9 Correct 0 ms 82880 KB Output is correct
10 Correct 0 ms 82880 KB Output is correct
11 Incorrect 0 ms 82880 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 82880 KB Output is correct
2 Correct 0 ms 82880 KB Output is correct
3 Correct 0 ms 82880 KB Output is correct
4 Correct 0 ms 82880 KB Output is correct
5 Correct 0 ms 82880 KB Output is correct
6 Correct 0 ms 82880 KB Output is correct
7 Correct 0 ms 82880 KB Output is correct
8 Correct 0 ms 82880 KB Output is correct
9 Correct 0 ms 82880 KB Output is correct
10 Correct 0 ms 82880 KB Output is correct
11 Incorrect 0 ms 82880 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 82880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 726 ms 82880 KB Output is correct
2 Correct 6 ms 82880 KB Output is correct
3 Correct 956 ms 82880 KB Output is correct
4 Execution timed out 1000 ms 82880 KB Execution timed out
5 Halted 0 ms 0 KB -