Submission #91326

#TimeUsernameProblemLanguageResultExecution timeMemory
91326YottaByteK blocks (IZhO14_blocks)C++14
53 / 100
284 ms17216 KiB
#include <stdio.h> #include <iomanip> #include <vector> using namespace std; const int N = 102; #define pb push_back #define ll long long #define int long long #define fr first #define sc second #define mk make_pair int b[N][N][N]; int n, a[N], k, t[N * 4], ans = 1e8; vector < pair < int, int > > lr[N]; void bld(int v = 1, int l = 1, int r = n) { if(l == r) { t[v] = a[l]; return; } else { int mid = l + r >> 1ll; bld(v + v, l, mid); bld(v + v + 1, mid + 1, r); } t[v] = max(t[v + v], t[v + v + 1]); } int getmx(int ql, int qr, int v = 1, int l = 1, int r = n) { if(l > qr || ql > r) return 0; if(ql <= l && r <= qr) return t[v]; int mid = l + r >> 1ll; return max(getmx(ql, qr, v + v, l, mid), getmx(ql, qr, v + v + 1, mid + 1, r)); } main() { scanf("%lld %lld", &n, &k); for(int i = 1; i <= n; i++) scanf("%lld", &a[i]); bld(); for(int i = 1; i <= k; i++) { for(int l = 1; l <= n; l++) { for(int r = 1; r <= n; r++) { b[i][l][r] = 1e9; } } } for(int r = 1; r <= n; r++) { b[1][1][r] = getmx(1, r); } for(int i = 2; i <= k; i++) { for(int l = i; l <= n; l++) { for(int r = l; r <= n; r++) { for(int j = 1; j < l; j++) { b[i][l][r] = min(b[i - 1][j][l - 1], b[i][l][r]); } b[i][l][r] += getmx(l, r); } } } for(int l = k; l <= n; l++) { ans = min(ans, b[k][l][n]); } //for(int r = 1; r <= n; r++) //{ //printf("%lld %lld ", 1ll, r); //printf("%lld\n", b[1][1][r]); //} printf("%lld\n", ans); } /** 5 2 4 5 1 2 3 5 2 1 2 3 4 5 5 1 1 2 3 4 5 **/ /** 5 3 1 2 3 4 5 100 50 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 **/

Compilation message (stderr)

blocks.cpp: In function 'void bld(long long int, long long int, long long int)':
blocks.cpp:29:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1ll;
             ~~^~~
blocks.cpp: In function 'long long int getmx(long long int, long long int, long long int, long long int, long long int)':
blocks.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1ll;
            ~~^~~
blocks.cpp: At global scope:
blocks.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...