Submission #21780

#TimeUsernameProblemLanguageResultExecution timeMemory
21780jjwdi0K blocks (IZhO14_blocks)C++11
0 / 100
19 ms90304 KiB
#include <bits/stdc++.h> #define log_N 18 using namespace std; int N, K; int A[100005]; int D[103][100005], C[103][100005]; int len[100005]; int par[100005][log_N]; void init() { int k = 0; for(int i=0; i<=N; i++) { if(i == (1 << k)) k++; len[i] = k; } } int RMQ(int s, int e) { return max(par[e][len[e-s]], par[s+(1<<len[e-s])-1][len[e-s]]); } void D_C(int k, int s, int e, int l, int r) { if(s > e) return; int mid = s + e >> 1; D[k][mid] = 2e9; for(int i=l; i<=r && i<mid; i++) { int v = D[k-1][i] + RMQ(i + 1, mid); if(D[k][mid] > v) D[k][mid] = v, C[k][mid] = i; } D_C(k, s, mid - 1, l, C[k][mid]); D_C(k, mid + 1, e, C[k][mid], r); } int main() { scanf("%d %d", &N, &K); for(int i=1; i<=N; i++) scanf("%d", A+i); for(int i=1; i<=N; i++) par[i][0] = A[i]; for(int i=1; i<log_N; i++) for(int j=1; j<=N; j++) par[j][i] = max(par[j][i-1], par[par[j][i-1]][i-1]); for(int i=1; i<=N; i++) D[1][i] = par[i][log_N-1]; for(int i=2; i<=K; i++) D_C(i, 1, N, 1, N); printf("%d\n", D[K][N]); }

Compilation message (stderr)

blocks.cpp: In function 'void D_C(int, int, int, int, int)':
blocks.cpp:23:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = s + e >> 1;
                 ^
blocks.cpp: In function 'int main()':
blocks.cpp:34:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &K);
                           ^
blocks.cpp:35:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d", 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...